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();

    
        }
    }
  • 相关阅读:
    CodeForces 687B Remainders Game
    CodeForces 689D Friends and Subsequences
    CSU 1810 Reverse
    生成树收录
    吃奶酪
    带逆向思维的并查集
    中位数定理
    种类并查集(关押犯人)
    带权并查集
    分层图
  • 原文地址:https://www.cnblogs.com/LIANQQ/p/3584755.html
Copyright © 2011-2022 走看看