StudyDSA logoStudyDSA

Command Palette

Search for a command to run...

Sign InSign Up
Sign Up

Data StructuresAlgorithmsBig-O NotationSystem DesignMachine LearningRoboticsAI Research

Definition
StudyDSA

Where complexity meets clarity.
By Armas Zarra.

Topics

  • Data Structures
  • Algorithms
  • Big-O Notation
  • Robotics
  • AI Research
  • Machine Learning

Practice

  • Blind 75
  • LeetCode 75
  • NeetCode 150

Legal

  • Privacy Policy
  • Terms of Service

© 2026 Armas Films LLC

IntroductionDesign Patterns

Design Patterns

Named, tested ways out of the problems object-oriented code keeps running into.

Definition

A design pattern is a reusable solution to a problem that keeps coming up in your code. Instead of copying and pasting code, it allows you to stay flexible and quickly implement new features as your project evolves. The patterns here come from the iconic Gang of Four, who cataloged them in 1994 and sorted them into three families: creational, structural, and behavioral.

Learning Path

There is no right or wrong order to learn design patterns in, so the order doesn't really matter. However, if you start at a certain section, I urge you to explore other design patterns in the same section so you learn the fundamental differences between them. I've also added fun exercises for each design pattern so you can actually practice implementing them!

Creational

Creational patterns deal with how objects get made. Instead of spamming constructor calls and setup logic all over your code, they keep object creation in one flexible place. There are five patterns that live here, from the everyday Factory Method to the goat Singleton.

Factory Method

Adding a new product type shouldn't mean editing every place that builds one. Subclasses decide what gets created.

CreatorProduct
Coming soon!

Abstract Factory

Keeps a whole family consistent: ask for the dark theme and every button, menu, and dialog comes back matching.

Factory
Coming soon!

Builder

A constructor with nine arguments is a trap. Build the object step by step, using only the steps you need.

obj
Coming soon!

Prototype

When setup is expensive or hidden, don't rebuild. Clone a working example and adjust the copy.

objcopy
Coming soon!

Singleton

One instance, guaranteed, reachable from anywhere. The most famous pattern, and the most abused one.

instance
Coming soon!
Structural

Structural patterns are about how objects fit together to build something bigger. The goal is to create flexible systems out of smaller parts. There are seven patterns here, and they all have their reasons to exist. I would spend extra time thinking about how and why some of these should be used over others in certain situations.

Adapter

Your code expects one interface and the library speaks another. A thin wrapper translates so neither has to change.

ClientAdapterAPI
Coming soon!

Bridge

Three shapes times four renderers shouldn't cost twelve classes. Split the two dimensions and they vary independently.

AbsImpl
Coming soon!

Composite

A file and a folder of a thousand files answer the same call. One thing and a group of things, treated identically.

Coming soon!

Decorator

Stack behaviors at runtime instead of multiplying subclasses. Wrap the object, add the feature, repeat.

core
Coming soon!

Facade

One simple call in front of thirty tangled ones. Callers get a clean entry point and the subsystem keeps its mess private.

Facade
Coming soon!

Flyweight

A million characters on screen, but only a handful of fonts. Share what repeats and memory stops exploding.

shared
Coming soon!

Proxy

A stand-in with the same interface as the real thing, free to lazy-load, cache, or guard before passing the call through.

ifaceClientProxyReal
Coming soon!
Behavioral

Behavioral patterns are the largest family. There are ten patterns here in total. They handle how objects talk to each other and split up the work, so the pieces can stay flexible instead of hardcoded together.

Chain of Responsibility

Nobody has to know who will handle the request. Each handler either takes it or passes it down the line.

Coming soon!

Command

Once a request is an object, you can queue it, log it, and reverse it. Every undo stack is built on this.

Command
Coming soon!

Iterator

Loop over a tree, a list, or a graph with the same code. The collection keeps its insides to itself.

Coming soon!

Mediator

Ten objects talking directly means 45 connections. Route everything through one hub and they stop knowing each other.

Coming soon!

Memento

Snapshots an object's private state without exposing it. Undo works because someone saved one of these.

state
Coming soon!

Observer

One change triggers many reactions without any hard wiring. Subscribers sign up and get notified the moment something happens.

Subj
Coming soon!

State

An object that acts like a different object in each state, without a giant switch statement in sight.

ctx
Coming soon!

Strategy

Swap the algorithm without touching the code that calls it. Sorting, pricing, and routing rules become plug-ins.

ctx
Coming soon!

Template Method

When five algorithms share one outline, write the outline once. Subclasses fill in only the steps that differ.

Coming soon!

Visitor

New operations on a stable family of classes, added without touching a single one of them.

Visitor
Coming soon!