Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8518289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:56:22+00:00 2026-06-11T05:56:22+00:00

for a small game I want to design two classes which should draw my

  • 0

for a small game I want to design two classes which should draw my Units. I have the classes Unit and Settler which extends Unit.

To draw them I have the classes UnitView and SettlerView.

Now UnitView has a method public void draw(Graphics g) and SettlerView should use the same method. The difference in the two classes should be in the way they are getting the information to draw the Unit. Let’s say Units are allways blue and Settlers have a Color depending on their health (which would be a field in Settler, where SettlerView has access to).

What would be a proper way to implement that? I want a clean design without public methods like setColor.

edit: This was my first approach:

public class UnitView {
    private Unit unit;
    public Color color; // I don't want to make it public. Setting it private + getter/setter does not seem to be different to me.
    private color calculateColor() { ...uses the information of unit... }
    public void draw(Graphics g) { ...something using the Color... }

}

public class SettlerView extends UnitView {
    private Settler settler;

    private color calculateColor() { ...this method overides the one of UnitView.... }
}

I want to use Polymorphism to call UnitView.draw. The key thing is the public field Color.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:56:24+00:00Added an answer on June 11, 2026 at 5:56 am

    you can always override the parent draw method.

    so for example if parent method is

    public void draw(Graphic g){
         g.setColor(blue);
    }
    

    the child class will have

    @Override
    public void draw(Graphic g){        
        if  (this.health > 50){
            g.setColor(green);
        }else{
            g.setColor(red);
        }
        super.draw(g); // if you want to call the parent draw and just change color
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have am writing a small game using Applet. I want to be able
I have a small multiplayer Flash game in which you can display a player
We have created a small game, it's working fine in devices, now we want
I have created a small game, in which some blocks are move around a
I'm building a small video game. I'm trying to do good oop/design. I have
I have a small Flash game which is written with AS3. My game sends
I'm developing a small game in Java and I have run into a problem
I'm doing a small game on Android 2.3.3 and I want to use openGLES.
Lets say i have created a small game with XNA. Now i can change
I'm the network programmer on a school game project. We want to have up

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.