package com.ruanyun;
/**
* @Auther: maxw
* @Date: 2018/11/12 11:23
* @Description:抽象工厂模式:与工厂方法模式不同的是,工厂方法模式中的工厂只生产单一的产品,而抽象工厂模式中的工厂生产多个产品。
* 还有个抽象工厂方法模式 只需要在建一个 ClothesFactory的实现工厂 就实现了该模式。
*/
public class Test7 {
public static void main(String args[]){
ClothesFactory adidasFactory = new AdidasFactory();
adidasFactory.createNeiyi().look();
adidasFactory.createDayi().look();
adidasFactory.createWaitao().look();
}
}
//定义一个衣服抽象类
abstract class Clothes{
abstract void look();
}
class Neiyi extends Clothes{
String name;
public Neiyi(String name) {
this.name = name;
}
@Override
void look() {
System.out.println(name+"内衣。。。");
}
}
class Dayi extends Clothes{
String name;
public Dayi(String name) {
this.name = name;
}
@Override
void look() {
System.out.println(name+"大衣。。。");
}
}
class Waitao extends Clothes{
String name;
public Waitao(String name) {
this.name = name;
}
@Override
void look() {
System.out.println(name+"外套。。。");
}
}
abstract class ClothesFactory{
abstract Neiyi createNeiyi();
abstract Dayi createDayi();
abstract Waitao createWaitao();
}
class AdidasFactory extends ClothesFactory{
@Override
Neiyi createNeiyi() {
return new Neiyi("阿迪");
}
@Override
Dayi createDayi() {
return new Dayi("阿迪");
}
@Override
Waitao createWaitao() {
return new Waitao("阿迪");
}
}