The quote below - taken from the Gang of Four - is very precise about the Factory Method. The Factory Method Design Pattern defines an interface for creating an object, but let sub classes decide which class to instantiate. Factory Method lets a class defer instantiating to sub classes.
Your code doesn't follow this. This is factory method pattern:
interfaceCarFactory{ICarCreateCar();}classElectricCarFactory:CarFactory{ICarCreateCar(){// logic to create a electric car}}classPetrolCarFactory:CarFactory{ICarCreateCar(){// logic to create a petrol car}}
Chapeau, this is spot on! I am guilty of adjusting the definition ever so slightly to my preferences, but you are right. Thank you for pointing that out.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The quote below - taken from the Gang of Four - is very precise about the Factory Method. The Factory Method Design Pattern defines an interface for creating an object, but let sub classes decide which class to instantiate. Factory Method lets a class defer instantiating to sub classes.
Your code doesn't follow this. This is factory method pattern:
Chapeau, this is spot on! I am guilty of adjusting the definition ever so slightly to my preferences, but you are right. Thank you for pointing that out.