Object Oriented Design Principles Cheat Sheet

Nil Seri
2 min readFeb 14, 2022

Concepts and Lists of Principles

Photo by Ronan Furuta on Unsplash

TL;DR

My aim here is not to go into detail but create a cheatsheet to quickly review before interviews to serve as a reminder.

OOP Concepts

  • Abstraction (hide complexity — blackbox, show only essential details. interfaces, abstract classes)
  • Encapsulation (private fields, public getter/setter. code update in one place)
  • Inheritance
  • Polymorphism (method overloading, method overriding)

Cohesion & Coupling

Cohesion = how related the functions within a single module are

Coupling = interdependencies between modules

High Cohesion, Low Coupling 👍🏻

SOLID Principles

  • Single Responsibility
  • Open-Closed Principle (open for extension, closed for modification)
  • Liskov’s Substitution (Rabbit extends Animal. classes should be substitutable)
  • Interface Segregation (instead of a single interface, prefer multiple smaller interfaces)
  • Dependency Inversion (Decoupling. depend on abstractions, interfaces)

GOF => interface > implementation, object decomposition > inheritance

Design Patterns
(Creational — Structural — Behavioral)

Best examples can be found here:

Creational

  • Factory Method
  • Abstract Factory (factory of factories)
  • Builder (complex objects using smaller objects)
  • Prototype (cloning)
  • Singleton (single instance)

Structural

  • Adapter (incompatible interfaces)
  • Bridge (decouple an abstraction from its implementation)
  • Composite (a class that contains group of its own objects)
  • Decorator (wrapper / no modifications on existing class, new functionality added)
  • Facade (hides complexity)
  • Flyweight (reduce weight of object creation, create if needed or reuse)
  • Proxy (a class represents functionality of another class — create a proxy class having original object)

Behavioral

  • Chain of Responsibility
  • Command (stock.buy returns BuyStock, stock.sell returns SellStock — both using Stock class)
  • Interpreter (language grammer, sql parsing)
  • Iterator (.next)
  • Mediator (communication between different classes)
  • Memento (restores to a previous state)
  • Observer (register, notify)
  • State (status, context)
  • Null Object (for do-nothing relationship, instead of returning null value)
  • Strategy (a class behavior or its algorithm can change at runtime)
  • Template (abstract class, method flow)
  • Visitor (execution algorithm of element can vary as and when visitor varies)
  • MVC

Happy Coding!

--

--

Nil Seri

I would love to change the world, but they won’t give me the source code | coding 👩🏻‍💻 | coffee ☕️ | jazz 🎷 | anime 🐲 | books 📚 | drawing 🎨