Jump to content
  • Advertisement
Sign in to follow this  
ogreblue

[java] Usability problem

This topic is 5411 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have problem in the implementation of a design for a Java program. I want to have a central game class that will call two different 'space ship' classes. When I compile it I want to be able to compile what ever different arrangement of 'space ship' classes I want, as there will be many variations, but I want to do this without changing the original game class. I hope I made ymself clear. Thanks for your time.

Share this post


Link to post
Share on other sites
Advertisement
What I am confused about is using initlializaing the space ship classes. IE if i was allowed to alter the game class I would do this in the nit() method

SpaceshipRandom SpaceShip_rnd;
SpaceshipMine SpaceShip_mine;

And then if i wanted to use the SpaceShipBezerk instead i would just do

SpaceshipRandom SpaceShip_rnd;
SpaceshipBezerk SpaceShip_bzk;

But what if i can't do this initialization?

Is it something to do with inheritance so I have a general SpaceShip class and derive different variations of this class?

Thanks for your help

Share this post


Link to post
Share on other sites
Quote:
Original post by ogreblue
What I am confused about is using initlializaing the space ship classes. IE if i was allowed to alter the game class I would do this in the nit() method

SpaceshipRandom SpaceShip_rnd;
SpaceshipMine SpaceShip_mine;

And then if i wanted to use the SpaceShipBezerk instead i would just do

SpaceshipRandom SpaceShip_rnd;
SpaceshipBezerk SpaceShip_bzk;

But what if i can't do this initialization?

Is it something to do with inheritance so I have a general SpaceShip class and derive different variations of this class?

Thanks for your help

yes, inheritance is one way, but an interface as mentioned before would also be a valid path. The difference between the inheritance thing and the interface thing is that the inheritance will copy functionallity, and you overwrite that functionality for your derived classes, where as the interface is more of a contract that the compiler enforces, throwing an error if you do not include all the requirements of the interface.

Personally, I would use the interface method, from the view point that the game engine needs certain functionality from the space ship, and therefore you create a contract between the game engine and any space ship subclasses.

Share this post


Link to post
Share on other sites
Sorry, I am not sure what you mean by 'interface'. Do you mean a class that will alow me this usaility or something else? If so how would I implement this. Could you point me in the direction of an article or similar post to this?

Thanks for your time.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If you really want help from others, you should show that you can help yourself. It can't be THAT hard to type "java interface" into a search engine...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!