I am seeking clarification on the exact purpose and definition of the Abstract Factory pattern.
According to the GoF (Gang of Four) book, the intent of the pattern is to:
Provide an interface for creating families of related or dependent
objects without specifying their concrete classes.
In the applicability section, it is recommended to use this pattern when:
- A system should be configured with one of multiple families of products.
- A family of related product objects is designed to be used together, and you need to enforce this constraint.
From this, it seems that the pattern is about isolating the client from the concrete implementation of a family of classes, ensuring that certain objects are used together as a family. For example:
public interface GuiAbstractFactory
{
IButton GetButton();
ITextBox GetTextBox();
}
However, I am confused because I have seen the term “Abstract Factory” used to refer to classes that expose a creation method for a single product, rather than a family of products. For example:
public interface ILoggerFactory
{
ILogger GetLogger(string name);
}
In particular, I have encountered blog posts and books that describe this usage:
Blog post by Mark Seemann
Blog post by Steven van Deursen’s
Seemann, M., & Van Deursen, S. (2019a). Dependency injection principles, practices, and patterns
Can someone clarify whether using the term “Abstract Factory” to refer to factories creating single products is correct? How does this usage align or conflict with the original GoF definition?