定义
为创建一组相关或相互依赖的对象提供一个接口,而且无需指定他们的具体类。
UML类图
模式案例
//产品
public class Product {
}
public class ConcreteProductA extends Product{
}
public class ConcreteProductB extends Product{
}
//产品蔟A
public class ConcreteProductA1 extends ConcreteProductA{
}
public class ConcreteProductA2 extends ConcreteProductA{
}
//产品蔟B
public class ConcreteProductB1 extends ConcreteProductB{
}
public class ConcreteProductB2 extends ConcreteProductB{
}
//工厂
public abstract class Factory {
abstract Product createProductA();
abstract Product createProductB();
}
public class ConcreteFactoryA extends Factory {
@Override
Product createProductA() {
return new ConcreteProductA1();
}
@Override
Product createProductB() {
return new ConcreteProductB1();
}
}
此篇文章仅作笔记
网友评论