学习心得
时间:2006-08-06 来源:netyang
GOF提出的23种模式,每一个我都会学习,然后再感悟,最后在这里写下心得.
Simple Factory Pattern(我简称为SFP)
简单工厂模式,书上说这种模式好像不是GOF4提出的,但是却是基础,于是也讲了一部分,对于SFP,感觉更像是OO的swich语句,只是这个swich控制的是类的实例,因为学的少,心得也就没有多少...继续学习.
书上关于工厂模式的一个应用范围的描述
When to Use a Factory Method
You should consider using a Factory method in the following situations.
A class can’t anticipate which kind of class of objects it must create.
当一个类不能预料必须创建那种类的实例时
A class uses its subclasses to specify which objects it creates.
当一个类用它的子类来指定它要创建的实例的时候
You want to localize the knowledge of which class gets created.
当你需要局部化的创建一些类的时候(翻译有问题)
There are several variations on the factory pattern to recognize.
1. The base class is abstract and the pattern must return a complete working class.
2. The base class contains default methods and these methods are called unless the default methods are insufficient.
3. Parameters are passed to the factory telling it which of several class types to return. In this case the classes may share the same method names but may do something quite different.
相关阅读 更多 +