[java] Dynamic Objects - Robot Example

Started by
1 comment, last by Spyder 23 years, 4 months ago
Problem. I have a bunch of robots that have different behaviors, attributes and skills. At the moment all robot types are predefined, but I would really like to assemble a custom robot on the fly.
consider this:
class LargeRobot extends MotherRobot implements Infravision, Flight, Turbo, Kick, Hostile

Next time around I want to create a LargeRobot that doesn''t have Flight but has Dive instead. How do I make this structure more dynamic? Would it be smarter to let LargeRobot have a vector of behaviors, attributes and skills that can shrink and grow? How would a smart java game programmer solve this basic task?
Advertisement
the design patterns forum has a thread on this very same topic, check all the threads and see if you can find it. They are using spaceships as their example. Or if you are looking for a simple solution just include all the abilities and then have boolean variables for whether they have the ability. Then if the ability is true, the method works normally, otherwise it does nothing.
quote:Or if you are looking for a simple solution just include all the abilities and then
have boolean variables for whether they have the ability. Then if the ability is true, the method works normally,
otherwise it does nothing.


That would work but it sounds like I''ll end up with 5000 if then statements to check all the boolean variables? And the class will be extremely large and waste memory space if a third of all the functions are not used?

This topic is closed to new replies.

Advertisement