抽象工厂模式

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

 

posted @ 2015-07-12 12:41  坏婷坏婷  阅读(164)  评论(0编辑  收藏  举报