Skip to content

About

Learn all 23 Gang of Four design patterns through simple explanations, visual diagrams, real-world examples, and modern code — available in English, Egyptian Arabic, Italian and Chinese.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sanfor2004

23 Design Patterns

Learn all 23 Gang of Four (GoF) design patterns with runnable Python and C++20 examples, diagrams, and explanations in English and Egyptian Arabic.

Sanfor2004 · Python + C++20

English · العربية المصرية

Start with a real problem. See where the simple solution bends. Learn the pattern, run Python and C++20, and decide whether the extra structure earns its place.

Two ways to study each pattern

Python reduces syntax overhead so the pattern's intent is easy to follow. Start with the small Python examples, then run and change them.

C++20 helps you study implementation details: Ownership, Lifetime, static typing, Runtime dispatch, RAII, and other engineering trade-offs. Keep both versions side by side; the same intent can use different language features.

Follow the recommended study order, starting with Strategy, Observer, Factory Method, Adapter, and Decorator. Continue through all 23; leave the harder global State questions in Singleton until last. Each pattern directory has both python/ and cpp/ with a README, runnable source, and expected output.

Why this repository exists

Patterns are easier to understand when you can trace a concrete problem through a small program. This repository puts the motivation, code, output, and trade-offs together so you can judge when an abstraction earns its cost.

Learn Design Patterns with Python and C++20

Run the examples

For Python, run python scripts/test_python.py from the repository root. No packages are needed.

For C++20, with CMake 3.20+ and a C++20 compiler installed, run from the repository root:

cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug
cmake --build build --config Debug
ctest --test-dir build -C Debug --output-on-failure

On Windows, use a Visual Studio developer shell. See the compiler and build notes for details.

How to navigate

Choose a category below or follow the learning path. Every pattern directory contains English and Egyptian Arabic lessons, a diagram, and python/ and cpp/ directories. Both lessons show the complete Python example first, followed by C++20 and each version's output.

Creational Pattern

How objects get created

  • Abstract Factory — Create related objects through one family interface. (Intermediate)
  • Builder — Assemble a configured object through named steps before producing the result. (Beginner)
  • Factory Method — Let a subclass choose the object used by a shared workflow. (Beginner)
  • Prototype — Create an independent object by cloning an existing configured object. (Intermediate)
  • Singleton — Restrict a type to one accessible instance, accepting the cost of shared global state. (Intermediate)

Structural Pattern

How objects fit together

  • Adapter — Translate an existing interface into the one a client expects. (Beginner)
  • Bridge — Separate two changing dimensions and connect them through composition. (Intermediate)
  • Composite — Treat a leaf and a tree of objects through the same operation. (Beginner)
  • Decorator — Add behavior by wrapping an object in another object with the same interface. (Beginner)
  • Facade — Offer a small entry point to a subsystem's common workflow. (Beginner)
  • Flyweight — Share immutable intrinsic data while keeping each occurrence's context separate. (Advanced)
  • Proxy — Control access to an object through a stand-in with the same interface. (Intermediate)

Behavioral Pattern

How objects communicate and behave

  • Chain of Responsibility — Pass a request along handlers that can stop or continue processing. (Intermediate)
  • Command — Turn an action into an object that can be stored and invoked later. (Intermediate)
  • Interpreter — Represent a small language as objects that evaluate its grammar rules. (Advanced)
  • Iterator — Traverse a collection through a stable access protocol. (Beginner)
  • Mediator — Move coordination between peer objects into a dedicated object. (Intermediate)
  • Memento — Save and restore an object's state without exposing snapshot internals. (Intermediate)
  • Observer — Notify subscribed objects when something they follow changes. (Beginner)
  • State — Let an object's current state determine its response and transitions. (Intermediate)
  • Strategy — Let an object choose among different algorithms for the same job. (Beginner)
  • Template Method — Fix an algorithm's sequence while subclasses implement selected steps. (Intermediate)
  • Visitor — Add operations across a stable set of element types using a separate visitor. (Advanced)

Understand the problem. Then earn the abstraction.

A pattern is a reusable design idea for a recurring problem—not a class diagram to copy everywhere. Start with simple code; introduce structure when a real change makes it useful.

  1. Meet the problem — A concrete example gives the design a reason to exist.
  2. Challenge the simple solution — Find the exact coupling or repetition that creates friction.
  3. Trace the design — Follow responsibilities, ownership, and trade-offs.
  4. Run and change Python and C++20 — Compare the output, try the challenge, and test the boundary.

Repository resources

Terminology policy

Translate the explanation, not the terminology. Pattern names, software terms, code identifiers, and interview expressions stay in English; each language explains their meaning.

Glossary

Share and track the launch

Use the launch pack for finished posts and images, including the GitHub social preview. The keyword and SEO tracker maps relevant search phrases to useful guides and records campaign results without assuming virality. Reproduce or adapt the campaign with the social media launch framework.

About

Learn all 23 Gang of Four design patterns through simple explanations, visual diagrams, real-world examples, and modern code — available in English, Egyptian Arabic, Italian and Chinese.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages