zoukankan      html  css  js  c++  java
  • 抽象工厂模式

    Boy.java

    package ff;
    
    public interface Boy {
        public void drawboy();
    }
    View Code

     Girl.java

    package ff;
    
    public interface Girl {
            public void drawgril();
    
    }
    View Code

    HNBoy.java

    package ff;
    
    public class HNBoy implements Boy {
    
        @Override
        public void drawboy() {
            // TODO Auto-generated method stub
            System.out.println("--新年系列的男孩子啊---");
        }
    
    }
    View Code

    HNGril.java

    package ff;
    
    public class HNGril implements Girl {
    
        @Override
        public void drawgril() {
            System.out.println("--新年系列的女孩子啊---");
    
        }
    
    }
    View Code

    MCBoy.java

    package ff;
    
    public class MCBoy implements Boy {
    
        @Override
        public void drawboy() {
            // TODO Auto-generated method stub
            System.out.println("--圣诞系列的男孩子啊---");
        }
    
    }
    View Code

    MCGril.java

    package ff;
    /*
     * 圣诞系列的女孩子啊
     */
    public class MCGril implements Girl {
    
        @Override
        public void drawgril() {
            System.out.println("--圣诞系列的女孩子啊---");
    
        }
    
    }
    View Code

    PersonFactory.java

    package ff;
    /*
     * 人物的实现接口;
     * 
     * */
    public interface PersonFactory {
        //男孩接口
        public Boy getboy();
        //女孩接口;
        public Girl getgirl();
    }
    View Code

    HNFactory.java

    package ff;
    
    public class HNFactory implements PersonFactory {
    
        @Override
        public Boy getboy() {
            // TODO Auto-generated method stub
            return new HNBoy();
        }
    
        @Override
        public Girl getgirl() {
            // TODO Auto-generated method stub
            return new HNGril();
        }
    
    }
    View Code

    MCFactory.java

    package ff;
    /*
     * 
     * 圣诞系列男孩加工厂;
     */
    public class MCFactory implements PersonFactory {
    
        @Override
        public Boy getboy() {
            // TODO Auto-generated method stub
            return new MCBoy();
        }
    
        @Override
        public Girl getgirl() {
            // TODO Auto-generated method stub
            return new MCGril();
        }
    
    }
    View Code

    test.java

    package ff;
    
    public class test {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            PersonFactory factory = new MCFactory();
            Girl gril = factory.getgirl();
            gril.drawgril();        
        }
    
    }
    View Code
  • 相关阅读:
    SOHO路由器
    SYN Flood
    Java线程池
    BIO
    Java虚拟机的基本结构
    Linux 的Ext2
    java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
    cassandra-CQL
    数列分段`Section II`(二分
    Exams(二分
  • 原文地址:https://www.cnblogs.com/zht0915/p/4640796.html
Copyright © 2011-2022 走看看