DELAPARRA
Index
Color
NL
Category: Design patterns

Abstract Factory

Explained by Updated

What is Abstract Factory?

Abstract Factory: Provide an interface for creating families of related objects without specifying their concrete classes. The Abstract Factory pattern gives you one interface for creating a family of related objects, without your code knowing which concrete classes it gets. You ask the factory for a button and a checkbox, and it returns a matching set.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about Abstract Factory

How is Abstract Factory used in practice?

The classic example is a UI toolkit with a light and a dark theme, or a Windows and a Mac version. Each factory produces components that fit together, and the rest of the code works with any of them.

What should you keep in mind with Abstract Factory?

In web applications you see it in drivers. A storage factory that hands out a local, S3 or FTP implementation is a simple version, and Laravel's managers for mail, cache and storage work along these lines. The pattern adds classes and indirection, so use it when you really have several families to swap between. For one implementation, a plain class is easier to read.

At a glance

CategoryDesign patterns
Explained by
Updated

More Design patterns terms

All terms starting with A

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.