Design Patterns

Recognising the 23 classic design patterns from a class diagram or from code, and implementing each in Python, Java and TypeScript.

  • 28 topics
  • 225 cards
  • 116 questions
  • Beginner to Advanced
Share

Foundations

What a design pattern is and how to read the class diagrams every pattern is drawn with.

  • What design patterns are: named, reusable solutions to recurring object-oriented design problems, how the 23 classic ones are grouped, and when one costs more than it saves.

    Beginner to Intermediate8 cards · 5 qnot started

  • Reading UML class diagrams: the boxes, lines and arrowheads every design pattern is drawn with, and how each relationship looks in code.

    Beginner to Intermediate8 cards · 5 qnot started

Creational Patterns

Controlling how objects are created, from choosing a class at runtime to assembling one in steps.

  • The Factory Method pattern: letting subclasses decide which class of object to create, so the code that uses the object never names it.

    Intermediate to Advanced9 cards · 4 qnot started

  • The Abstract Factory pattern: creating whole families of related objects through one interface, so a program can switch every product at once.

    Intermediate to Advanced8 cards · 4 qnot started

  • The Builder pattern: constructing a complex object step by step, so a constructor with a dozen optional parameters is never needed.

    Intermediate to Advanced9 cards · 4 qnot started

  • The Prototype pattern: creating new objects by copying a configured one, and the shallow copy trap that comes with it.

    Intermediate to Advanced8 cards · 4 qnot started

  • The Singleton pattern: guaranteeing a class has exactly one instance with a global access point, and why it is the most criticised of the 23.

    Intermediate to Advanced9 cards · 4 qnot started

  • Choosing a creational design pattern: telling Factory Method, Abstract Factory, Builder, Prototype and Singleton apart, and when a plain constructor is enough.

    Intermediate to Advanced5 cards · 4 qnot started

Structural Patterns

Combining objects into larger structures by wrapping, sharing and nesting them, and telling the wrappers apart.

  • The Adapter pattern: wrapping an existing class so it fits the interface a client already expects, without changing either side.

    Intermediate to Advanced8 cards · 4 qnot started

  • The Decorator pattern: adding behaviour to an object by wrapping it in others with the same interface, and how it differs from Python's @ syntax.

    Intermediate to Advanced8 cards · 5 qnot started

  • The Facade pattern: one simple interface in front of a complex subsystem, with the subsystem's classes still there for the cases the facade does not cover.

    Intermediate to Advanced8 cards · 4 qnot started

  • The Proxy pattern: a stand-in with the same interface as a real object that controls when and whether calls reach it, and the self-call it never sees.

    Intermediate to Advanced9 cards · 4 qnot started

  • The Composite pattern: treating a single object and a group of objects the same way, as in files and folders.

    Intermediate to Advanced8 cards · 4 qnot started

  • The Bridge pattern: splitting what something is from how it is done into two hierarchies, so they grow without multiplying classes.

    Intermediate to Advanced8 cards · 4 qnot started

  • The Flyweight pattern: sharing the common part of many small objects so that a program holding millions of them still fits in memory.

    Intermediate to Advanced8 cards · 4 qnot started

  • Choosing a structural design pattern: telling Adapter, Decorator, Facade, Proxy, Composite, Bridge and Flyweight apart by what each wrapper is for.

    Intermediate to Advanced5 cards · 4 qnot started

Behavioural Patterns

Dividing work and communication between objects, and telling apart the patterns that look alike in a diagram.

  • The Strategy pattern: putting each interchangeable algorithm behind one interface so the caller chooses it, and why in Python the strategy is often a function.

    Intermediate to Advanced9 cards · 4 qnot started

  • The Observer pattern: letting many objects subscribe to one and be told when it changes, and the listener that is never unsubscribed.

    Intermediate to Advanced9 cards · 4 qnot started

  • The Command pattern: turning a request into an object that can be queued, logged or undone, and what each command must remember to undo itself.

    Intermediate to Advanced9 cards · 4 qnot started

  • The Template Method pattern: fixing the order of an algorithm's steps in a base class and letting subclasses supply the steps that differ.

    Intermediate to Advanced9 cards · 4 qnot started

  • The Iterator pattern: walking a collection one element at a time without knowing how it is stored, and why a Python generator can be walked only once.

    Intermediate to Advanced9 cards · 4 qnot started

  • The State pattern: giving each state of an object its own class, so behaviour changes when the state changes, and deciding which class chooses the next state.

    Intermediate to Advanced8 cards · 4 qnot started

  • The Chain of Responsibility pattern: passing a request along a chain of handlers until one deals with it, and ending every chain with an answer for requests nobody accepts.

    Intermediate to Advanced8 cards · 4 qnot started

  • The Mediator pattern: routing the communication between many objects through one coordinator, and counting the links it removes.

    Intermediate to Advanced8 cards · 4 qnot started

  • The Memento pattern: saving an object's state as a snapshot only that object can read, so it can be restored later, and keeping the snapshots from filling the memory.

    Intermediate to Advanced8 cards · 4 qnot started

  • The Visitor pattern: adding operations over a fixed set of classes as separate visitor classes, how double dispatch finds the right method, and why a new element class is costly.

    Intermediate to Advanced9 cards · 4 qnot started

  • The Interpreter pattern: representing each rule of a small language as a class, evaluating a sentence as a tree of those objects, and knowing that parsing is a separate job.

    Intermediate to Advanced8 cards · 4 qnot started

  • Choosing a behavioural design pattern: telling Strategy, State, Template Method, Command, Observer, Mediator, Chain of Responsibility and Decorator apart by who decides and how many objects take part.

    Intermediate to Advanced5 cards · 5 qnot started