Kit oh
Kit oh

Reputation: 29

Can a 'Factory' Design Pattern have more than 1 abstract type in a factory?

Please note; Factory, not Abstract Factory.

Say, there is an interface Shape with concrete classes like Pentagon. Let's say an abstract class Quadrilateral implements Shape and has its own concrete types like Square.

Is this still considered a Factory Method?

Upvotes: 0

Views: 783

Answers (1)

jaco0646
jaco0646

Reputation: 17104

Firstly, the Shape interface represents the product created by the factory. So long as the factory returns Shape instances, any other details of the product inheritance hierarchy are irrelevant to both the factory and its clients.

Secondly, the tutorial linked in the comment describes what Head First Design Patterns calls a Simple Factory. It is not a GoF design pattern. You can read my take on the GoF patterns here.

Finally, a warning: beware any blog or tutorial using the phrase "Factory Pattern". There is no single pattern named "Factory". Factory is a category of patterns including instances both inside and outside the GoF book. There are at least four factory patterns in common use.

Upvotes: 1

Related Questions