zoukankan      html  css  js  c++  java
  • 转--设计模式之多个工厂方法模式,静态方法模式

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

    复制代码
    /**
     * @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();

        }
    }
    复制代码
  • 相关阅读:
    GUI起头
    最大公约数
    最小公倍数
    最大公约数、最小公倍数
    质数——筛选法
    质数——用已有质数求质数
    质数——6N±1法
    质数——1到n遍历法
    微服务的优势
    收到offer!
  • 原文地址:https://www.cnblogs.com/awkflf11/p/4370534.html
Copyright © 2011-2022 走看看