posts - 37,comments - 7,trackbacks - 0
1. Both FM an AFM create objects. But FM do it through inheritance and AFM through object composition. 
      To create objects using FM, you need to extends a class and override a factory method. the whole point of the FM Pattern is that your're using a subclass to do your own creation for you. In that way, clients only need to know the abstract type they are using, the subclass worries about the concrete type. So,  in other words, FM keep clients decoupled from the concrete types.
      AFM provides an abstrct type for creating a family of products. Subclasses of this type define how those products are produced. To use the factory, your instantiate one and pass it into some code that is written against the abstract type. So, like FM, the clients are decoupled from the actual concrete products they use.

2. AFM group together a set of related products
3. AFM often use factory methods to implement it's concrete factories. 

4. use  AFM whenever you have families of products you need to create and you want to make sure your clients create products that belong together. use FM to decouple your client code from the concrete classes you need to instantiate, or if you don't know ahead of time all the concrete classes you are going to need , just subclass and implement the factory method.
 
posted on 2005-08-12 11:03 Dave 阅读(156) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: