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:
Wow

Example 2:

Input:
ToyFactory tf = ToyFactory();
toy = tf.getToy('Cat');
toy.talk();
Output:
Meow

Solution

Last updated

Was this helpful?