A factory method Pattern

来源:互联网 发布:记账软件手机版 编辑:程序博客网 时间:2024/04/30 09:30

A factory method handles object creation and encapsulates it in a subclass. This decouples the client code in the superclass from the object creation code in the subclass.

public abstract class PizzaStore {

       public Pizza orderPizza (String type ) {
            Pizza pizza;

            pizza = createPizza ( type );

            pizza.prepare();
            pizza.bake();

            return pizza();

        }

  protected abstract Pizza createPizza (String type) ;

}

 

image