Object Oriented Design Principles Cheat Sheet

Object Oriented Design Principles Cheat Sheet

Thanks to the original writer and article :

https://senoritadeveloper.medium.com/


TL;DR

My aim here is not to go into detail but create a cheat sheet 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, and interfaces)

GOF?=> interface > implementation, object decomposition > inheritance


Design Patterns

(Creational — Structural — Behavioral)

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!

要查看或添加评论,请登录

社区洞察

其他会员也浏览了