【题目描述】
Factory is a design pattern in common usage. Please implement a ToyFactory which can generate proper toy based on the given type.
工厂模式是一种常见的设计模式。请实现一个玩具工厂 ToyFactory 用来产生不同的玩具类。可以假设只有猫和狗两种玩具。
【题目链接】
www.lintcode.com/en/problem/toy-factory/
【题目解析】
系统设计基础题,用class Dog和class Cat继承interface Toy,然后在ToyFactory里按照String type生成需要的类就可以了。
【参考答案】
网友评论