Toy Factory
Description
Factory is a design pattern in common usage. Please implement a ToyFactory
which can generate proper toy based on the given type.
Example
Example 1:
Input:
ToyFactory tf = ToyFactory();
Toy toy = tf.getToy('Dog');
toy.talk();
Output:
WowExample 2:
Input:
ToyFactory tf = ToyFactory();
toy = tf.getToy('Cat');
toy.talk();
Output:
MeowSolution
Last updated
Was this helpful?