简单工厂模式
工厂模式 1.简单工厂模式(又称静态工厂方法模式) 2.工厂方法模式(又称多态性工厂模式) 3.抽象工厂模式(工具箱模式) 简单工厂模式举例: 具体实现: public class 简单工厂模式 { public static void main(String[] args) throws BadException { Friut apply = Factory.create("Apply"); apply.grow(); } } /** * 抽象产品 */ interface Friut{ /** * 种植 */ void plant(); /** * 生长 */ void grow(); /** * 收获 */ void harvest(); } /** * 具体产品1 */ class Apply implements Friut{ public void plant() { System.out.println("Apply plant()"); } public void grow() { System.out.println("Apply grow()"); } public void harvest() { System.out.println("Apply harvest()"); } } /** * 具体产品2(梨) */ class Pear