Design Patterns are a way to solve common object oriented design problems. But understanding and learning design patterns is hard and takes time. Looking at a pattern is like looking at a solution without a problem, unless you’ve encountered the problem in the past.
This course aims to help you understand & implement Creational Design Patterns. Each pattern is explained with multiple examples and through modern C++. This helps you understand how the pattern can be implemented efficiently using language features. The examples do not involve cars, pizzas, ducks, coffee, etc. These topics are rarely used while building real-world software. Instead I provide real-world examples written in Modern C++. These examples will compile & execute on any platform that supports a C++ compiler.
This is how the course teaches creational patterns.
-
The intent, structure of the pattern is explained through UML class diagram.
-
Basic implementation details of the pattern are explained.
-
The pattern is implemented in a simple example.
-
You get familiar with the overall implementation of the pattern.
-
Another example is introduced that has design issues the pattern aims to resolve.
-
We examine the issues and refactor the code by applying the design pattern step by step.
-
Alternative scenarios & examples are explained along with differences between them. You also learn how to decide between different alternatives.
-
I discuss the pattern in context of C++ and how to tweak it for performance, reusability & maximum flexibility.
-
Finally, you’ll learn when to use the pattern and its pros & cons.
This is an intensive discussion that spans multiple lectures. At the end of each section, you’ll understand the pattern in depth and can apply it in your code or easily clear any design interview.
Introduction
Instructor & course introduction.
Understand what "pattern" means.
Quick introduction to UML class diagrams.
Understand what SOLID principles are. This video explains single responsibility & open closed principle.
This lecture explains the Liskov Substitution Principle
This lecture explains the interface segregation & depending inversion principle.
Gives a quick overview of creational patterns.
Slide deck.
Singleton
Demo project of Singleton pattern
Explains the intent of this pattern & its basic implementation.
Shows a simple implementation of the pattern.
Demonstrates the issues in a class and why it needs to be a singleton.
The Logger is refactored to a singleton. Additionally, it is made non-copyable.
The example is modified for lazy instantiation.
Learn about the issues with lazy instantiation & how to resolve them.
Demonstrates the problem of using singleton in a multithreaded application.
Learn how double-checked locking pattern can fail in some scenarios.
Demonstrates how to implement Meyer's singleton.
Demonstrates the usage of call_once function.
This lecture demonstrates how to use CRTP idiom to implement a singleton class through inheritance.
An example that does not require a singleton implementation for singularity.
Learn what monostate pattern is and how to implement it.
This lecture compares singleton & monostate that will help you decide which one to use.
Learn about the several issues with incorrect implementation of the Singleton Pattern.
Learn how to implement registry of singletons.
This lecture demonstrates how to implement the registry using lazy instantiation.
In this lecture, I discuss pros & cons of the singleton design pattern.
Factory Method
Demo project of Factory Method pattern
Introduction of the factory method, its intent & structure.
This video shows a simple example without the factory method design pattern.
In this lecture, I implement the factory method in the previous example.
I explain the example of a framework in which we'll later implement the factory method.
The application framework is implemented without the pattern. This helps us understand the issues with the design.
In this lecture, you'll learn how to implement the factory method in the application framework.
Demonstrates an alternative implementation of the factory method.
This example shows several examples of how & why a factory method can be implemented as a global function.
Continues the discussion of factory methods as functions.
Understand the pros & cons of the factory method and when to apply it.
Object Pool
Learn the intent, structure and implementation details of the object pool pattern.
This video demonstrates a simple example of the pattern.
The lecture starts with an example of a game that can benefit from pooling large number of game objects.
In this lecture, I demonstrate how to use pooling for Missile class objects.
I update the example to support multiple types of Actors.
This lecture shows the implementation of Acquire & Release methods.
This videos shows how to reduce dependency on concrete classes through a factory.
Learn how to create a generic object pool that can work with any class.
This video improves the implementation with custom allocator.
Understand the pros and cons of the object pool pattern and when to use it.
Abstract Factory
Demo project of Abstract Factory
Introduction to the pattern, its intent & structure.
This lecture demonstrate a simple example that will be implemented later with Abstract Factory.
The example in the previous example is modified and refactored to use the Abstract Factory.
This lecture explains the example that will be used for explained the Abstract Factory pattern.
Continue understanding the implementation of the database framework.
We add the Sql database classes & understand their usage.
In this lecture, I'll add the MySql database classes.
We'll use the database framework classes from the client through macros & conditional statements.
Macros & conditional statements are inflexible for creating instances of database classes. In this lecture, we'll attempt to use the factory method design pattern.
The db framework is refactored to use the Abstract Factory design pattern.
Understand the pros & cons of this pattern.
Prototype
Demo project of the Prototype pattern
Introduction to the pattern and its intent.
Understand the basics of cloning and how to use the prototype pattern to implement it.
Implementation of the prototype pattern with a basic example.
Introduction to the example used for prototype design pattern.
In this part, I'll add the Animation & the Vehicle class.
This lecture continues with implementation of the Vehicle subclasses.
This lecture adds the GameManager that creates the instances of the Vehicle subclasses.
Understand why cloning is useful.
In this lecture, I implement the prototype pattern through shallow copy.
Continuation of the previous lecture. You'll also see the issues with shallow cloning.
We refactor the game to use deep copy to prevent issues with shallow copy.
Understand how we can use different instances of the same class with variations in states. This reduces the number of classes in the game.
In this lecture, we'll remove extra car & bus classes. Instead, by varying the state of few objects, we'll simulate objects of other classes.
In this lecture, we implement the prototype manager.
In this part, we complete the implementation of prototype manager.
We'll modify our implementation to use smart pointers to avoid manual memory management.
Understand the pros & cons of this pattern and when to use it.
Builder
Introduction of the pattern, along with its intent & structure.
Basic implementation of the builder pattern.
Introduction to the File example.
This lecture explains the design issues with the File example.
In this lecture, we refactor the code to use the builder pattern.
Usage of the File class through the builder pattern.
This lecture demonstrates how to implement a modern builder without creating too many classes.
This lecture shows an alternative implementation of the builder that uses a fluent interface.
Understand the pros & cons of the builder pattern and when to use it.