扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
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);
}
}
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。