Chapter 6. Creational Patterns: Abstract Factory and Builder

The creational patterns introduce a very popular concept in design patterns: factories. Factories are classes that handle the instantiation of related objects without subclassing. We saw in Chapter 5 how the Factory Method pattern can hide the class name from the place where an object is instantiated. The Abstract Factory pattern takes this one step further, creating families of related or dependent objects. The Builder pattern offers additional flexibility in terms of the combination of objects being built.

Abstract Factory Pattern

Role

This pattern supports the creation of products that exist in families and are designed to be produced together. The abstract factory can be refined to concrete factories, each of which can create different products of different types and in different combinations. The pattern isolates the product definitions and their class names from the client so that the only way to get one of them is through a factory. For this reason, product families can easily be interchanged or updated without upsetting the structure of the client.

Illustration

A scourge of modern society is the huge number of fakes on the market. The products of many famous brands are copied and presented for sale, often as the real thing. Sometimes the copies are identified up front as replicas, so the customer is aware of what he is buying. However, often the customer is unaware (or maybe does not care) from which factory the ...

Get C# 3.0 Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.