当前位置:编程学习 > JAVA >>

设计模式--创建模式--抽象工厂模式--java

intent
•Provide an interface for creating families of related ordependent objects without specifying their concrete classes.
•提供一个接口使得不使用具体的类来创建有关系的或者依赖关系的对象族。
 
UML
Applicability
•a system should be independent of how its products arecreated, composed, and represented.
•一个系统要独立于产品的创建、组合、表示。
•a system should be configured with one of multiplefamilies of products.
•一个系统需要由多个产品族中的一个来配置。
•a family of related product objects is designed to beused together, and this constraint youneed to enforce 。
•产品族被用来一起联合使用并强制一些约束。
•you want to provide a class library of products, and youwant to reveal just their interfaces, not their implementations.
•你需要提供一些产品类库,并且你仅仅使用他的接口。而不去实现他们。
 
Consequences
•It isolates concrete classes.
•分离了具体的类。
•It makes exchanging product families easy.
•使产品族更容易改变。
•It promotes consistency among products.
•有利于产品族的一致性
•Supporting new kinds of products is difficult.
•支持新种类产品比较困难。
 
产品等级结构
多个产品等级结构
产品族
具体的UML
 
TankGameUML
•在TankGame中元素分为矢量图版和图片版。所以对于产品角色来讲有两套产品族。两个工厂。
 
工厂方法UML与抽象工厂比对
工厂方法着重于Creator中的FactoryMethod()
抽象工厂着重于AbstractFactory
1、当增加产品等级结构
此时便不满足开闭原则。
2、当增加产品族
增加产品族,则满足开闭原则。
 
补充:软件开发 , Java ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,