工厂类:
*Delare plant method class
*We can now define plant class,note that it is in the same leve as produ
class pizzastore definition abstract.
public section.
methods:
* This method is used to order the concrete product
orderpizza
importing pz_name1 type string
returning value(pz) type ref to pizza.
protected section.
methods:
* This method seems like a factory
* Because this method is abstract, the subclass must instantiate thi
* This method must have a return value, which is the concrete produc
createpizza abstract
importing pz_name2 type string
returning value(pz) type ref to pizza.
endclass.
class pizzastore implementation.
method orderpizza.
data: pz_ref type ref to pizza.
* This is the key part of factory method pattern
* We use factory method to create concrete product
call method createpizza
exporting pz_name2 = pz_name1
receiving pz = pz_ref.
* Other methods
call method:
pz_ref->prepare,
pz_ref->bake,
pz_ref->cut,
pz_ref->box.
* Return the concrete product which have been created
pz = pz_ref.
endmethod.
endclass.
*We can now define plant class,note that it is in the same leve as produ
class pizzastore definition abstract.
public section.
methods:
* This method is used to order the concrete product
orderpizza
importing pz_name1 type string
returning value(pz) type ref to pizza.
protected section.
methods:
* This method seems like a factory
* Because this method is abstract, the subclass must instantiate thi
* This method must have a return value, which is the concrete produc
createpizza abstract
importing pz_name2 type string
returning value(pz) type ref to pizza.
endclass.
class pizzastore implementation.
method orderpizza.
data: pz_ref type ref to pizza.
* This is the key part of factory method pattern
* We use factory method to create concrete product
call method createpizza
exporting pz_name2 = pz_name1
receiving pz = pz_ref.
* Other methods
call method:
pz_ref->prepare,
pz_ref->bake,
pz_ref->cut,
pz_ref->box.
* Return the concrete product which have been created
pz = pz_ref.
endmethod.
endclass.