3 Design Patterns CPP Creational m3 Slides
3 Design Patterns CPP Creational m3 Slides
Dmitri Nesteruk
@dnesteruk dn@activemesa.com http://activemesa.com
Module Overview
Motivation
Point Initialization Example
Factory Method
Factory External Class
Factory Inner Class
Abstract Factory
Motivation
Object creation logic becomes too convoluted
Constructor is not descriptive
- Name mandated by name of containing type
- Cannot overload with same sets of arguments with different names
- Can turn into ‘optional parameter hell’
Object creation (non-piecewise, unlike Builder) can be outsourced to
- A separate function (Factory Method)
- That may exist in a separate class (Factory)
- You can even have a hierarchy of classes with Abstract Factory
A separate component responsible solely
Factory for the wholesale (not piecewise) creation
of objects.
Abstract A factory construct used to construct
Factory object in hierarchies.
Factory A function that helps create objects. Like a
Method constructor but more descriptive.
Module Overview