首页 > 其他 > 详细

转--设计模式之多个工厂方法模式,静态方法模式

时间:2015-03-27 06:21:21      阅读:100      评论:0      收藏:0      [点我收藏+]

接着上篇文章的简单工厂模式,做以下修改,即可实现多个工厂方法模式

技术分享
/**
 * @author ieasy360_1
 * 工厂类
 */
public class SenderFactory {

//    public Sender sendproduce(String type)
//    {
//        if(type.equals("qq"))
//        {
//            return new Qq();
//        }
//        else if(type.equals("wx"))
//        {
//            return new Weixin();
//        }
//        else
//        {
//            return null;
//        }
//    }
    public Sender qqsend()
    {
        return new Qq();
    }
    public static Sender weixinsend()
    {
        return new Weixin();
    }
}
技术分享

具体调用,一个是采用静态方法调用

技术分享
/**
 * @author ieasy360_1
 *
 */
public class Test1 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        SenderFactory factory = new SenderFactory();
        Sender sender = factory.qqsend();
        sender.send();

          Sender sender1 = SenderFactory.weixinsend();
          sender1.send();

    }
}
技术分享

转--设计模式之多个工厂方法模式,静态方法模式

原文:http://www.cnblogs.com/awkflf11/p/4370534.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!