Template Design Pattern:
Parent class(abstract class or interface) properties are inherited in subclass, the contradictory methods in parent class are overridden with the subclass methods.
Strategy Design Pattern:
Parent class properties are inherited in subclass,the contradictory methods are removed and converted into a new class and it says that overriding should not be used much in programs
Question 1: So whether I should design my program based on Template Design Pattern or Strategy Design Pattern
This is My Example To Create Pizza:
Parent Class: Pizza-addCheese(),addmeat(),addSpices(),addCondiments()
NonVegPizza extends Pizza- (addCheese(),addmeat(),addSpices(),addCondiments()) VegPizza extends Pizza-(addSpices(),addCondiments())//I dont want the addmeat()&addCheese() methods in VegPizza .
I Know only at runtime that whether Pizza is going to be Veg or Nonveg Pizza.
Question 2: Suggest me whether it should use Strategy Design Pattern or Template Design Pattern in the following example
Aucun commentaire:
Enregistrer un commentaire