二十四种设计模式:抽象工厂模式(使用频率5个星,共5星)
interface Button{ public void display(); } public class SpringButton implements Button{ public void display(){ system.out.print("浅绿色按钮"); } } public class SummerButton implements Button{ public void display(){ system.out.print("浅蓝色按钮"); } } interfac TextField{ public void display(); } public class SpringTextField implements TextField{ public void display(){ system.out.print("浅绿色文本框"); } } public class SummerTextField implements TextField{ public void display(){ system.out.print("浅蓝色文本框"); } } interface Factory{ public Button createButton(); public TextField createTextField(); } public class SpringFactory implements Factory{ public Button createButton(); public TextField createTextField(); } public class SummerFactory implements Factory{ public Button createButton(); public TextField createTextField(); } public class App{ public void main(String args[]){ Factory factory ; Button button; TextField textField; factory =new SpringFactory(); button =factory.createButton(); textField=factory.createTextField(); button.display(); textField.display(); } }
抽象工厂模式:提供一个创建一系列相关或相互依赖的对象接口,而无须指定它们具体的类。抽象工厂模式又称为Kit模式,它是一种对象创建模式