Isn't the whole point of factory is to make complex initializations easier? I am not able to see how this can be applicable when factory is not just a wrapper for new. Why would you even use factory (and look for a simplification) when constructor is already more than enough?
No, the point of the factory pattern is to create an object that implements a particular interface (IAnimal) without knowing the class of the object. You can take a look at an example here.
Thank you for pointing this. I'm a Unity developer and in Unity we cannot use constructors at all (it breaks the engine). Plus, interfaces are sometimes anti-pattern (if not most of the time). This sometimes create confusion.
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.
Isn't the whole point of factory is to make complex initializations easier? I am not able to see how this can be applicable when factory is not just a wrapper for new. Why would you even use factory (and look for a simplification) when constructor is already more than enough?
No, the point of the factory pattern is to create an object that implements a particular interface (
IAnimal
) without knowing the class of the object. You can take a look at an example here.Thank you for pointing this. I'm a Unity developer and in Unity we cannot use constructors at all (it breaks the engine). Plus, interfaces are sometimes anti-pattern (if not most of the time). This sometimes create confusion.