A factory method Pattern

    技术2025-07-14  15

    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) ;

    }

     

    最新回复(0)