OOP & Design Patterns Interview Guide — SOLID + 23 Patterns | Interview Prep Buddy

Object-Oriented Design & GoF Patterns Hub

Master the foundations of clean software architecture. Explore SOLID Principles, 23 Gang-of-Four Design Patterns, UML Class Relationships, and Refactoring Best Practices.

5SOLID Principles
23GoF Patterns
4OOP Pillars
100%Production-Ready
🏛️

The SOLID Principles Cheat-Sheet

5 core guidelines for maintainable and scalable Object-Oriented software.

S

Single Responsibility Principle (SRP)

class OrderRepository { save(order: Order): void { ... } }

"A class should have one, and only one, reason to change."

❌ Violation:Mixing database access, business rules, and HTML rendering inside a single Order class.
✅ SOLID Fix:Separate into Order, OrderRepository, and OrderInvoiceRenderer classes.
O

Open/Closed Principle (OCP)

interface PaymentStrategy { pay(amount: number): void; }

"Software entities should be open for extension, but closed for modification."

❌ Violation:Using massive if-else or switch blocks whenever adding a new payment method.
✅ SOLID Fix:Define a PaymentStrategy interface; add new payment classes without editing existing code.
L

Liskov Substitution Principle (LSP)

interface FlyingBird extends Bird { fly(): void; }

"Subtypes must be substitutable for their base types without breaking application behavior."

❌ Violation:Ostrich inheriting from Bird and throwing UnsupportedOperationException on fly().
✅ SOLID Fix:Split interfaces into FlyingBird and NonFlyingBird to maintain LSP contracts.
I

Interface Segregation Principle (ISP)

interface Printer { print(doc: Document): void; }

"Clients should not be forced to depend on interfaces they do not use."

❌ Violation:Creating a bloated MultiFunctionPrinter interface with print(), scan(), and fax().
✅ SOLID Fix:Split into smaller, focused interfaces: Printer, Scanner, FaxMachine.
D

Dependency Inversion Principle (DIP)

constructor(private sender: MessageSender) {}

"High-level modules should not depend on low-level modules. Both should depend on abstractions."

❌ Violation:NotificationService directly instantiating SendGridApi with `new SendGridApi()`.
✅ SOLID Fix:Inject a MessageSender interface into NotificationService constructor.

23 Gang-of-Four Design Patterns (23)

Reusable solutions to common object-oriented design challenges.

Creational

Factory Method

Defines an interface for creating objects, but lets subclasses decide which class to instantiate.

💡 Typical Production Use-Case:Payment processor creation (Stripe/PayPal/Razorpay)
Creational

Abstract Factory

Provides an interface for creating families of related or dependent objects without specifying concrete classes.

💡 Typical Production Use-Case:Cross-platform UI widgets (Mac vs Windows buttons)
Creational

Builder Pattern

Separates the construction of a complex object from its representation, enabling step-by-step construction.

💡 Typical Production Use-Case:HTTP Request / Database Query builder
Creational

Singleton Pattern

Ensures a class has only one instance while providing a global access point to this instance.

💡 Typical Production Use-Case:Thread pool manager, Database connection pool
Creational

Prototype Pattern

Creates new objects by copying an existing instance (cloning) to save expensive initialization.

💡 Typical Production Use-Case:Game character cloning, Document templates
Structural

Adapter Pattern

Allows objects with incompatible interfaces to collaborate by converting one interface into another.

💡 Typical Production Use-Case:Integrating third-party Analytics SDKs
Structural

Decorator Pattern

Attaches new behaviors to objects dynamically by placing them inside special wrapper objects.

💡 Typical Production Use-Case:Coffee add-ons (Milk, Sugar), Stream encryption wrappers
Structural

Facade Pattern

Provides a simplified interface to a library, a framework, or any other complex set of classes.

💡 Typical Production Use-Case:One-click checkout hiding Inventory, Payment, and Shipping
Structural

Composite Pattern

Composes objects into tree structures to represent part-whole hierarchies cleanly.

💡 Typical Production Use-Case:File system folders/files, Organization org chart
Structural

Proxy Pattern

Provides a surrogate or placeholder for another object to control access, lazy load, or log.

💡 Typical Production Use-Case:Hibernate lazy loading, Rate-limiting proxy
Structural

Bridge Pattern

Decouples an abstraction from its implementation so that the two can vary independently.

💡 Typical Production Use-Case:Remote Control (Abstraction) vs TV Device (Implementation)
Structural

Flyweight Pattern

Fits more objects into available RAM by sharing common parts of state among multiple objects.

💡 Typical Production Use-Case:Text editor character rendering, Game particle effects
Behavioral

Strategy Pattern

Defines a family of algorithms, encapsulates each one, and makes them interchangeable at runtime.

💡 Typical Production Use-Case:Sorting algorithms, Route calculation (Shortest, Fastest)
Behavioral

Observer Pattern

Defines a subscription mechanism to notify multiple subscriber objects about events.

💡 Typical Production Use-Case:Pub/Sub events, YouTube channel subscription
Behavioral

State Pattern

Allows an object to alter its behavior when its internal state changes, appearing to change its class.

💡 Typical Production Use-Case:Vending machine states, Order fulfillment workflow
Behavioral

Command Pattern

Encapsulates a request as a standalone object containing all information about the request.

💡 Typical Production Use-Case:Undo/Redo history, Job queue task execution
Behavioral

Chain of Responsibility

Passes requests along a chain of handlers until one of the handlers processes the request.

💡 Typical Production Use-Case:Middleware authentication pipeline, Support ticket routing
Behavioral

Template Method

Defines the skeleton of an algorithm in the superclass but lets subclasses override specific steps.

💡 Typical Production Use-Case:Data parser (CSV, JSON, XML) framework
Behavioral

Iterator Pattern

Accesses elements of an aggregate object sequentially without exposing its underlying representation.

💡 Typical Production Use-Case:Traversing Binary Tree / Custom Collection
Behavioral

Mediator Pattern

Reduces chaotic dependencies between objects by restricting direct communications to a mediator.

💡 Typical Production Use-Case:Air Traffic Control tower, Chat room server
Behavioral

Memento Pattern

Saves and restores the previous state of an object without revealing the details of its implementation.

💡 Typical Production Use-Case:Text editor undo snapshots, Game save state
Behavioral

Visitor Pattern

Separates algorithms from the objects on which they operate by adding visitor operations.

💡 Typical Production Use-Case:Compiler AST syntax tree evaluation
Behavioral

Interpreter Pattern

Evaluates sentences in a language by defining a grammatical representation.

💡 Typical Production Use-Case:SQL query parser, Regular expression engine
© 2026 Object-Oriented Design & GoF Patterns Studio · Form follows function.