4 Removed ambiguous language
source | link

An increasingly popular definition of factory method is: a static method of a class that returns an object of that class' type. But unlike a constructor, the actual object it returns might be an instance of a subclass. enter image description here

From : https://sourcemaking.com/design_patterns/factory_method

Doesn't it violate OCP?

I have also seen this in production code.

What would be the correct implementation?

I can think of a separate Creator class with static method, which returns subclass objects. It My proposed solution is clearly not abstract factory as it doesn't create families of products. It, also it doesn't fit any of the GoF creational pattern. So I am skeptical about my solution.

An increasingly popular definition of factory method is: a static method of a class that returns an object of that class' type. But unlike a constructor, the actual object it returns might be an instance of a subclass. enter image description here

From : https://sourcemaking.com/design_patterns/factory_method

Doesn't it violate OCP?

I have also seen this in production code.

What would be the correct implementation?

I can think of a separate class with static method. It is clearly not abstract factory as it doesn't create families of products. It doesn't fit any of the GoF creational pattern. So I am skeptical about my solution.

An increasingly popular definition of factory method is: a static method of a class that returns an object of that class' type. But unlike a constructor, the actual object it returns might be an instance of a subclass. enter image description here

From : https://sourcemaking.com/design_patterns/factory_method

Doesn't it violate OCP?

I have also seen this in production code.

What would be the correct implementation?

I can think of a separate Creator class with static method, which returns subclass objects. My proposed solution is clearly not abstract factory as it doesn't create families of products, also it doesn't fit any of the GoF creational pattern. So I am skeptical about my solution.

3 edited tags
| link
2 added 77 characters in body
source | link

An increasingly popular definition of factory method is: a static method of a class that returns an object of that class' type. But unlike a constructor, the actual object it returns might be an instance of a subclass. enter image description here

From : https://sourcemaking.com/design_patterns/factory_method

Doesn't it violate OCP?

I have also seen this in production code.

What would be the correct implementation?

I can think of a separate class with static method. But It is clearly not abstract factory as it doesn't create families of products. It doesn't fit any of the GoF creational pattern. So I am skeptical about my solution.

An increasingly popular definition of factory method is: a static method of a class that returns an object of that class' type. But unlike a constructor, the actual object it returns might be an instance of a subclass. enter image description here

From : https://sourcemaking.com/design_patterns/factory_method

Doesn't it violate OCP?

I have also seen this in production code.

What would be the correct implementation?

I can think of a separate class with static method. But it doesn't fit any of the GoF creational pattern. So I am skeptical about my solution.

An increasingly popular definition of factory method is: a static method of a class that returns an object of that class' type. But unlike a constructor, the actual object it returns might be an instance of a subclass. enter image description here

From : https://sourcemaking.com/design_patterns/factory_method

Doesn't it violate OCP?

I have also seen this in production code.

What would be the correct implementation?

I can think of a separate class with static method. It is clearly not abstract factory as it doesn't create families of products. It doesn't fit any of the GoF creational pattern. So I am skeptical about my solution.

1
source | link