简单理解:工厂A即可生产产品A也可生产产品B...
超能的工厂,既可以生产肥皂又可以生产洗衣服。。。
package Creating.pratice; public class AbstractFactoryM { public static void main(String[] args) { Animal animal = new AFactoryP().newAnimal(); animal.showAnimal(); Fruit fruit = new AFactoryP().newFruit(); fruit.showFruit(); } } interface AbstractFactoryP{ public Animal newAnimal(); public Fruit newFruit(); } class Animal{ public void showAnimal(){ System.out.println("动物出来了!"); } } class Fruit{ public void showFruit(){ System.out.println("水果熟了!"); } } class AFactoryP implements AbstractFactoryP{ @Override public Animal newAnimal() { return new Animal(); } @Override public Fruit newFruit() { return new Fruit(); } }