creational
Abstract Factory
Provide an interface for creating families of related objects without specifying their concrete classes.
Sometimes objects only make sense in matched sets. A Windows button belongs with a Windows checkbox; a MySQL connection belongs with a MySQL query builder. If client code instantiates each piece directly, nothing stops it from accidentally mixing a Mac button with a Windows scrollbar. Abstract Factory solves this by making the whole family the unit of choice rather than the individual object.
A furniture store sells matched sets — Victorian style gives you all Victorian items; Modern gives you all Modern.
Key Concepts
1
You define a factory interface with one creation method per product type — createButton(), createCheckbox(), and so on. Each concrete factory implements that interface for one coherent family and is guaranteed to return parts that belong together. The client holds only the factory interface and the product interfaces, so it can render an entire UI, or talk to an entire database backend, without ever naming a concrete class. Swapping the whole family is then a one-line change: hand the client a different factory.
createButton()createCheckbox()
2
Use it for cross-platform UI toolkits, interchangeable database or cloud backends, and theme systems where every component must visually match. The trade-off is rigidity in one direction: adding a new product type to the family means changing the factory interface and every concrete factory that implements it. Abstract Factory is comfortable adding new families but resistant to adding new kinds of product, so it fits domains where the set of product types is stable but the number of families keeps growing.