package mode;
/**
* 设计模式之抽象工厂模式
* @author gaoq
* @date 2015-12-5 下午4:28:39
*/
public class AbstractFactoryMode {
/**
* 发送功能接口
* @author gaoq
* @date 2015-12-5 下午4:40:28
*/
interface Sender{
public void SenderMsg();
}
/**
* 邮件发送功能
* @author gaoq
* @date 2015-12-5 下午4:40:40
*/
class MailMsg implements Sender{
@Override
public void SenderMsg() {
System.out.println("你好,我是163");
}
}
/**
* 短信发送功能
* @author gaoq
* @date 2015-12-5 下午4:41:24
*/
class SmsMsg implements Sender{
@Override
public void SenderMsg() {
System.out.println("你好,我是飞秋");
}
}
/**
* 生产发送消息功能实体类的接口
* @author gaoq
* @date 2015-12-5 下午4:41:38
*/
interface produce{
public Sender getSender();
}
/**
* 邮件发送体的工厂类
* @author gaoq
* @date 2015-12-5 下午4:42:40
*/
class MailMsgFactory implements produce{
@Override
public Sender getSender() {
return new MailMsg();
}
}
/**
* 短息发送体的工厂类
* @author gaoq
* @date 2015-12-5 下午4:43:21
*/
class SmsMsgFactory implements produce{
@Override
public Sender getSender() {
return new SmsMsg();
}
}
/**
* 抽象工厂模式类测试入口
* @param args
*/
public static void main(String[] args) {
/**发送短息**/
SmsMsgFactory factory = new AbstractFactoryMode().new SmsMsgFactory();
SmsMsg sms = (SmsMsg) factory.getSender();
sms.SenderMsg();
/**发送邮件**/
MailMsgFactory mailFactory = new AbstractFactoryMode().new MailMsgFactory();
MailMsg mail = (MailMsg) mailFactory.getSender();
mail.SenderMsg();
}
}