vendredi 2 novembre 2018

Factory Method Design Pattern seems to just be an If/Else or Switch statement. What am I missing?

So I have been trying to brush up on my design patterns (thank you college for not teaching these...) and the Factory Method design pattern is giving me trouble.


Will refer to this Factory Method Design Pattern In C# for the sake of keeping the question area from having a ton of code in it.


I understand that there are a few parts to it:

  1. Product - CreditCard
  2. ConcreteProduct- MoneyBackCreditCard, TitaniumCreditCard, PlatinumCreditCard
  3. Creator- CardFactory
  4. ConcreteCreator- MoneyBackCardFactory, TitaniumCardFactory, PlatinumCardFactory

When I look at the implementation though, all I see is a set of objects (with a common ancestor) whose constructor is decided and called based on some variable.

I assume there is something more correct? Last I knew, creating an object in a if/else or switch statement did not define a design pattern. I don't understand what makes this special.

Thanks to all who respond.

Aucun commentaire:

Enregistrer un commentaire