I think your robot should have a list of ports i.e. a number of injected components each robot may have. Your Robot
class will be a container of RobotPart
s. You can have specific parts to have specific interfaces. RobotHand
extends RobotPart
and Robot
class has a field that holds a list of RobotHand
implementations (you can limit it to 2 hands, but in general case there could be more). You can do the same with RobotHead
that will inherit from RobotPart
and also there will be a field in Robot
class holding implementation of RobotHead
. In its turn RobotHead
may hold a list of RobotEye
implementations and so on. Then your specific Robot
implementations may inherit their behavior from base class or take advantage of configuration e.g. by using RobotBladeHand
s if available.
↧
Answer by Andrey Adamovich for Design pattern help
↧