设计模式之工厂模式之简单工厂模式(一)
2013-12-30 14:36
267 查看
public class FactoryTest { public static void main(String[] args) { SendFactory factory = new SendFactory(); Sender sender = factory.produce("sms"); sender.Send(); } } interface Sender { public void Send(); } class MailSender implements Sender { @Override public void Send() { System.out.println("this is mailsender!"); } } class SmsSender implements Sender { @Override public void Send() { System.out.println("this is sms sender!"); } } class SendFactory { public Sender produce(String type) { if ("mail".equals(type)) { return new MailSender(); } else if ("sms".equals(type)) { return new SmsSender(); } else { System.out.println("请输入正确的类型!"); return null; } } }
结果:
this is sms sender!
相关文章推荐
- iOS 设置 setContentOffset 时序
- 解决oracle 的一系列错误:ORA-00603 ORA-01595 ORA-00600
- bash正则表达式部分知识点
- c语言经典面试题
- 发散式button按钮动画效果
- 电磁场理论基础
- linux自动挂载文件系统详解
- split方法使用的经验。
- 将C1Chart数据导出到Excel
- tail -f和tail -F的区别
- 黑马程序员--高新技术(二)
- android中图片的三级cache策略(内存、文件、网络) 一
- Integer Inquiry(大数加法)
- linux编程学习笔记(五) make的使用和Makefile
- AMImpl 中 执行sql语句的例子
- VirtualBox 修改UUID实现虚拟硬盘复制
- Redis 在新浪微博中的应用
- curl使用
- ContentProvider(4):怎样获取其他APP分享的数据
- 用iptables实现NAT