c# - Factory Pattern but with object Parameters -


itemprop = "text">

Take the following classic factory patterns:

  public interface IPizza {decimal value {get; }} Public Square HamAndMushroom Pizza: Ipiza {decimal ipizza.price {get {return 8.5m; }}} Public Intangible Classroom PizzaFactory {Public Abstract IPizza MakePizza (ItalianPizzaFactory.PizzaType pizzaType); } Public class ItalianPizzaFactory: PizzaFactory {public enum PizzaType {HamMushroom, Deluxe, Hawaii} Public Override IPizza MakePizza (PizzaType pizzaType) {Case (PizzaType) {Case: PizzaType.HamMushroom: New HamAndMushroomPizza Return (;); Case pizza type Hawaiian: Return the new Hawaiian Pizza (); Default: New argument throwing exception ("Pizza type" + Pizza type + "Not recognized."); }}}  

What if there is a specific requirement for concrete implementation on the creation of a parameter (or several) of concrete pizzas. For example, suppose a parameter called the HamAndMushroom factory, requires MushroomType and would require an illustration of this parameter object?

You can add parameters to the manufacturer method (s) of your factory However, if the number of parameters is more It's getting (this will be more than 2-3 for me), and especially if some or all of the parameters are optional with the proper default values, then you can change the factory in turn. / P>

That is why that can be particularly suitable for pizza, where usually the same layer of topping, is just different (combinations). A builder model is very near the usual way of ordering "Salami, Tomato, Mecca and a Double Paneer Pizza" Otoho may want to define helpful factory methods for "predefined" pizza, e.g.

or createHawaiiPizza which is then built internally using a builder to make a pizza with toppings for that kind of pizza Does.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -