Design Patterns in C++

Personal project, December 2023

Between the months of November and December I wanted to dig deeper on software engineering, so I decided to study and implement some design patterns. In particular the fundamental one from the Gang of Four (GoF).

I created a repository that acts as a collection of C++ implementations of these patterns. The GoF patterns are all presents but in the future I’m planning to add also the “extra” patterns (at the moment only the null object is present).

Creational

Design PatternDescription
Abstract FactoryProvides an interface for creating families of related or dependent objects without specifying their concrete classes.
BuilderSeparates the construction of a complex object from its representation, allowing the same construction process to create different representations.
Factory MethodDefines an interface for creating an object but leaves the choice of its type to the subclasses.
PrototypeCreates new objects by copying an existing object, known as the prototype.
SingletonEnsures a class has only one instance and provides a global point of access to that instance.

Structural

Design PatternDescription
AdapterAllows classes with incompatible interfaces to work together by wrapping its own interface around that of an already existing class.
BridgeDecouples an abstraction from its implementation so that the two can vary independently.
CompositeComposes zero-or-more similar objects so that they can be manipulated as one object.
DecoratorDynamically adds/overrides behavior in an existing method of an object.
FacadeProvides a simplified interface to a large body of code.
FlyweightReduces the cost of creating and manipulating a large number of similar objects.
ProxyProvides a placeholder for another object to control access, reduce cost, and reduce complexity.

Behavioral

Design PatternDescription
Chain of ResponsibilityDelegates commands to a chain of processing objects.
CommandCreates objects that encapsulate actions and parameters.
InterpreterImplements a specialized language.
IteratorAccesses the elements of an object sequentially without exposing its underlying representation.
MediatorAllows loose coupling between classes by being the only class that has detailed knowledge of their methods.
MementoProvides the ability to restore an object to its previous state (undo).
ObserverIs a publish/subscribe pattern, which allows some observer objects to see an event.
StateAllows an object to alter its behavior when its internal state changes.
StrategyAllows one of a family of algorithms to be selected on-the-fly at runtime.
Template MethodDefines the skeleton of an algorithm as an abstract class, allowing its subclasses to provide concrete behavior.
VisitorSeparates an algorithm from an object structure by moving the hierarchy of methods into one object.

During this exploration I discovered many interesting aspects of software engineering by exploring this field, especially a concept of scope level design patterns. Some design patterns can be applied directly on the repository (code level, so in micro), like the GoF patterns or concurrency patterns for MT paradigms.

Other design patterns acts on an higher level of abstraction, and these are called architectural patterns. Some of them are widely known like the MVC (Model-View-Controller) or n-tier, but most of them are new to me.

In the future I would like to write a blog post about them with diagrams and explanations, seems a good idea for studying them in a fun way 😁

Manuel Pagliuca
Manuel Pagliuca
M.Sc. in Computer Science

My studies include Real-Time Graphics, GP-GPU, Artificial Intelligence and Distributed Systems.