package abstractfactory;

public interface ProductA ...{
}

package abstractfactory;

public class ProductA1 implements ProductA ...{
}

package abstractfactory;

public class ProductA2 implements ProductA ...{
}

package abstractfactory;

public interface ProductB ...{
}

package abstractfactory;

public class ProductB1 implements ProductB ...{
}

package abstractfactory;

public class ProductB2 implements ProductB ...{
}

package abstractfactory;

public interface Creator ...{
public ProductA factoryA();
public ProductB factoryB();
}

package abstractfactory;

public class Creator1 implements Creator ...{

public ProductA factoryA() ...{
return new ProductA1();
}

public ProductB factoryB() ...{
return new ProductB1();
}
}

package abstractfactory;

public class Creator2 implements Creator ...{

public ProductA factoryA() ...{
return new ProductA2();
}

public ProductB factoryB() ...{
return new ProductB2();
}
}

package abstractfactory;

public class Client ...{
ProductA pa;
ProductB pb;

public static void main(String[] args) ...{
Client client = new Client();
Creator1 c1 = new Creator1();
client.pa = c1.factoryA();
client.pb = c1.factoryB();
System.out.println(client.pa);
System.out.println(client.pb);
}
}
用户评论