this statement asks me what kind of design pattern applied, firstly , tell me what to build toys, as they are only 3 types of play, and none is related eg with some color, would apply the factory method.
But apart it tells me that the Toys can be turned off and on, which makes me think that this would be a command pattern (or state).
I can mix 2 patterns in a final solution?
We want to build 3 kinds of toys : Pokemon , Barbie and Superman . They feature animation actions associated with their off and on , these actions are different for each type of toy. Explain what design pattern and would use the class diagram Perform final design .
thanks
You can use the interface and implementation akash89 described except the
ShowAnimation
interface and its implementation is the Strategy Pattern. In the strategy pattern you'll have an interface with interchangeable implementations, in this case your toys.The State Pattern assumes that the internal behaviour changes of the object when you call some method. This is not the case in question.
A normal Factory Pattern is more than enough. You'll just create objects with (in the case of akash89) the
ShowAnimation
interface on which you can call the on and off animations. (However I would change the interface toIToy
because a toy factory would create toys, not ShowAnimations ;) )An Abstract Factory will create factories itself. For example, you could have an abstract factory that will create a factory for boy-specific toys or a factory for girl-specific toys. Each factory will then create barbies, pokemons and/or a superman.