[Java] 纯文本查看 复制代码
interface IProduct1 {
public void show();
}
interface IProduct2 {
public void show();
}
class Product1 implements IProduct1 {
public void show() {
System.out.println("这是1型产品");
}
}
class Product2 implements IProduct2 {
public void show() {
System.out.println("这是2型产品");
}
}
interface IFactory2 {
public IProduct1 createProduct1();
public IProduct2 createProduct2();
}
class Factory2 implements IFactory2 {
public IProduct1 createProduct1() {
return new Product1();
}
public IProduct2 createProduct2() {
return new Product2();
}
}
public class Client2 {
public static void main(String[] args) {
IFactory2 factory = new Factory2();
factory.createProduct1().show();
factory.createProduct2().show();
}
}