★ 对抽象工厂模式的一点理解
2007-05-01 16:35
197 查看
| |||||
package abstractfactory; // 接口 A interface ProductA { void sayHello(String name); } // 类的具体的实现 一 class ProductA1 implements ProductA { public void sayHello(String name) { System.out.println("hello : " + name); } } // 类的实现 二 class ProductA2 implements ProductA { public void sayHello(String name) { System.out.println("hello : " + name); } } //接口 B interface ProductB { ........... } // 类的具体的实现一 class ProductB1 implements ProductB { .......... } // 类的具体的实现二 class ProductB2 implements ProductB { ........... } // 返回对象实例 的接口 interface Creator { public ProductA factoryA(); public ProductB factoryB(); } // 抽象工厂的接口具体的实现 一 class Creator1 implements Creator { public ProductA factoryA() { return new ProductA1(); } public ProductB factoryB() { return new ProductB1(); } } // 抽象工厂的具体实现 二 class Creator2 implements Creator { public ProductA factoryA() { return new ProductA2(); } public ProductB factoryB() { return new ProductB2(); } } // 测试方法 public class Test { public static void main(String[] args) { ProductA pa; ProductB pb; Creator1 creator1 = new Creator1(); pa = creator1.factoryA(); pa.sayHello("张迪"); } } | |||||
| |||||
<iframe src="http://aosustudio.com.cn/ad/GoogleSerch.htm" frameborder="0" width="100%" scrolling="no" height="30"></iframe> | |||||
相关文章推荐
- 写一点opengl的初步入门理解
- 我对sip的一点理解
- 对于Linux内核tty设备的一点理解
- 对数据预处理的一点理解[ZZ]
- 关于rman备份保留策略“恢复窗口”的一点理解
- Android:对Service的一点理解2
- 【机器学习】感知机的一点理解
- 【机器学习】感知机的一点理解
- 关于对Python作用域的一点理解
- 对linux中进程创建的一点理解(2)
- 关于反射的一点理解(一)
- 关于 *Object 的一点理解,肯定不全对 希望和大家交流
- 我对opensocia的一点l理解
- NSRunLoop的一点理解
- 关于fourcc的一点理解
- 关于C#中Thread.Join()的一点理解
- 关于fisher判别的一点理解
- 菜鸟对使用AIDL的一点理解
- 对双缓冲技术的一点理解!
- 对S3C2440片上总线(AMBA)的一点理解