public class Test { public static void main(String[] args) { Factories.test(); } } /* 设计模式之禅中的工厂模式是这样的,先定义好工厂和产品的接口,实现各个产品, 产品无需为工厂编写任何代码.工厂通过传产品类的class对象来生成一个产品,这 其中用到了反射方面的东西,我觉着这中方案会更好一点. 案例中的方案,虽然利用接口降低了耦合,但是还是有点不太舒服 */ interface Service { void m…
/** * 接口应用 */ public class Main { public static void main(String[] args) { Person p = new Person("fish7"); p.setIsay(new BeforeGong()); p.say(); p.setIsay(new AfterGong()); p.say(); } } class Person{ //只有在运行期才和say行为关联起来,这就叫面向接口编程 private String…
抽象工厂模式(Abstract Factory Pattern)是工厂方法模式的进一步抽象,其英文原话"Provide an interface for creating families of related or dependent objects without specifying their concrete classes",翻译,"为创建一组相关或相互依赖的对象提供一个借口,无需指定它们的详细类".抽象工厂模式一般是用于创一族产品,而且这族产品分不同的…