标签:
//接口
public interface Sender{ public void Send(); }
//实现类1
public classMailSender implements Sender{ public void Send(){ System.out.println("mail sender"); } }
//实现类2
public class SMSSender implements Sender{ public void Send(){ System.out.println("SMS sender"); } }
//静态工厂
public class SenderFactory{ public static Sender mailSender(){ return new MailSender(); } public static Sender smsSender(){ return new SMSSender(); } }
public class FactoryTest{ public static void main(String[] args){ SenderFactory.smsSender().Send(); SenderFactory.mailSender().Send(); } }
标签:
原文地址:http://www.cnblogs.com/liubo6/p/4501040.html