名称
Abstract Factory
结构
![](/images/load.gif)
意图
提供一个创建一系列相关或相互依赖对象的接口,而无需指定它们具体的类。
适用性
一个系统要独立于它的产品的创建、组合和表示时。
一个系统要由多个产品系列中的一个来配置时。
当你要强调一系列相关的产品对象的设计以便进行联合使用时。
当你提供一个产品类库,而只想显示它们的接口而不是实现时。
它的一个重要的作用就是改变应用程序的外观.让我们通过国内一个用java实现了的的例子来看一看抽象工厂模式是如何在应用层被使用的。假设你才买了一套住宅,屋顶有一个花园,而你需要设计一下花园的布局。花园右侧有一个花台,边上需要种一排植物,中心需要种主体植物。根据风格的不同,花园可以被设计为典雅型、使用型和懒人型。 这是用别人的java例子改成的.
pre {font-family:"Courier New", Courier, Arial; font-size: 12px;}
.operator {color: #000000;}
.keyword {color: #993300;}
.identifier {color: #000087;}
.properties {color: #000087;}
.identifier2 {color : #000087;}
.linecomment, .blockcomment {color: #808080;}
.string {color: #0000FF;}
class Garden
{
private function Garden()
{
}
public function getShade():Plant// 花台中的植物
{
return ;
}
public function getCenter():Plant// 中间的植物
{
return;
}
public function getBorder():Plant// 边上的植物
{
return;
}
}
// ElegantGarden.as (典雅型)
class ElegantGarden extends Garden
{
public function getShade():Plant
{
return new Plant("郁金香");
}
public function getCenter():Plant
{
return new Plant("榕树");
}
public function getBorder():Plant
{
return new Plant("兰草");
}
}
// PracticalGarden.as(实用型)
class PracticalGarden extends Garden
{
public function getShade():Plant
{
return new Plant("葡萄");
}
public function getCenter():Plant
{
return new Plant("石榴");
}
public function getBorder():Plant
{
return new Plant("丝瓜");
}
}
// LasyGarden.as(懒人型)
class LasyGarden extends Garden
{
public function getShade():Plant
{
return new Plant("月季");
}
public function getCenter():Plant
{
return new Plant("茶花");
}
public function getBorder():Plant
{
return new Plant("竹");
}
}
此源文件中有一个grant skinner的GForm类,开发Form应用的时候,可以参考一下。