This article describes the Abstract Factory Design Pattern design pattern. This is a creational design pattern, a category of design pattern used by software engineers, when writing computer programs.

Table of Contents

Introduction

The Abstract Factory Design Pattern pattern is a design pattern, used in software engineering to grouping similar objects without needing to specifying their concrete classes. This allows the developer to outline the methods and objects of the final concrete factories, so that all share an expected set of methods and classes. Objects are typically just represented as interfaces, allowing concrete objects to be varied, but always have the important shared features.

This pattern defines an Abstract Factory (CarFactory) which has Abstract Products (ICar), which is used by the Client to create Concrete Factories (SaloonCarFactory, HatchbackCarFactory) with Concrete Products (SaloonCar, HatchbackCar)

This pattern is defined as a Creational design pattern because it defines the base templates for factories that create objects.

Return to Top


Benefits

Allows the application to be more portable and extensible.
Allows new derived types to be added, without changing any core/shared properties or methods.
Reduces the amount of conditional logic needed (eg "if car is Saloon, do this, else do that")

 

 

Return to Top


Examples of the pattern

A Real world example would be a car factory, that produced several models of car. You would instantiate a concrete implementation of the "car factory" class to make a saloon car, or hatchback model. That concrete factory can both make cars, totally different cars, but both factories have "AddWheels" and "InsertEngine" methods. Each of the resulting car objects have Colour and NumberPlate properties, as well as Brake and Accelerate methods, because all cars are of type ICar.
 

 

Return to Top


See Also

Link to domain parent articles and related articles in TechNet Wiki.

 

Return to Top


Community Resources

These are the external links, including links to Microsoft and TechNet sites that are non-Wiki

 

Return to Top


References section

Use this section if you pulled source material and ideas from other sites, blogs, or forums. Make sure you have permission from authors to use their material.

 

 

Return to Top