想要成为高薪程序猿的看这里!
2015-12-10 15:23
253 查看
/* GUIFactory example -- The output should be either "I'm a WinButton" or "I'm an OSXButton" depending on which kind of factory was used. Note that the Application has no idea what kind of GUIFactory it is given or even what kind of Button that factory creates.*/ interface GUIFactory { public Button createButton(); } class WinFactory implements GUIFactory { public Button createButton() { return new WinButton(); } } class OSXFactory implements GUIFactory { public Button createButton() { return new OSXButton(); } } interface Button { public void paint(); } class WinButton implements Button { public void paint() { System.out.println("I'm a WinButton"); } } class OSXButton implements Button { public void paint() { System.out.println("I'm an OSXButton"); } } class Application { public Application(GUIFactory factory){ Button button = factory.createButton(); button.paint(); } } public class ApplicationRunner { public static void main(String[] args) { new Application(createOsSpecificFactory()); } public static GUIFactory createOsSpecificFactory() { int sys = readFromConfigFile("OS_TYPE"); if (sys == 0) { return new WinFactory(); } else { return new OSXFactory(); } } }
相关文章推荐
- java—连接池 C3p0 DBCP
- 20151210笔记本电话在ubuntu10.04下获取YUYV格式的图像
- 美团云创建用户名和工作区
- 谈论高并发(二十二)解决java.util.concurrent各种组件(四) 深入了解AQS(二)
- 接口测试返回值验证方式---返回值为json长串
- 运输层—UDP
- hql 在oracle数据库下的简单应用
- Arduino - 红外接收
- 报表系统格集模型-格集表示法
- POPTEST学员就业面试题目!!!!!
- 伪造客户端IP实例
- Remove Duplicates from Sorted List
- . /lib/x.sh
- BlueDroid介绍
- C++ 10模板方法模式
- IOS中得block代码块的定义及使用
- ElasticSearch优化配置
- 清理/var/log/messages的脚本
- linux 安装rabbitmq
- gem install bundle 安装失败