Study Guide

Software DesignSOLID Principles

Cheat sheet + 20 flashcards covering SOLID, DRY, KISS, YAGNI, coupling & cohesion, composition, and code smells.

12 concept areas 20 flashcards Track your score
Quick Reference

Cheat Sheet

SOLID Overview

The Five Principles

SSingle Responsibility — one reason to change
OOpen/Closed — extend, don't modify
LLiskov Substitution — subtypes must be substitutable
IInterface Segregation — no forced unused methods
DDependency Inversion — depend on abstractions
S — SRP

Single Responsibility

A class should have only one reason to change. If a class handles both business logic and database access, a DB schema change forces you to touch business logic code.

Fix: split into separate classes — one for logic, one for persistence.

O — OCP

Open / Closed

Open for extension, closed for modification. Add new behaviour by writing new code — not by editing existing, tested code.

Pattern: use Strategy, Decorator, or Plugin patterns so new variants slot in without touching the core.

L — LSP

Liskov Substitution

A subtype must be substitutable for its base type without breaking the program.

Classic violation: Square extends Rectangle — setting width on a Square also changes height, breaking callers that expect independent dimensions.

I — ISP

Interface Segregation

Clients should not be forced to implement methods they don't use.

Split one large "fat" interface into many small, focused ones. A Printable class shouldn't also be forced to implement scan() and fax() it doesn't need.

D — DIP

Dependency Inversion

High-level modules should not depend on low-level modules — both depend on abstractions.

Inject dependencies through interfaces. A OrderService depends on a PaymentGateway interface, not on StripePayment directly — swap providers without changing OrderService.

Principles

DRY · KISS · YAGNI

DRY: Don't Repeat Yourself — every piece of logic has one authoritative home. Duplication = two bugs to fix instead of one.
KISS: Keep It Simple — prefer the simplest working solution.
YAGNI: You Aren't Gonna Need It — build for today's requirements.

Coupling

Low Coupling

Coupling = degree to which modules depend on each other's internal details.

High coupling: changing module A breaks B, C, D.
Low coupling: modules are independent — change A without touching others.

Achieve with: interfaces, dependency injection, event systems.

Cohesion

High Cohesion

Cohesion = how closely related a module's responsibilities are.

High cohesion: everything in the class serves one clear purpose — easy to understand and reuse.
Low cohesion: a "God class" doing many unrelated things — hard to change, test, or reuse parts of.

OOP

Composition over Inheritance

Favour has-a (composition) over is-a (inheritance).

Deep inheritance chains tightly couple children to parent — a change propagates everywhere. Composing small, focused objects is more flexible: swap a component without rewriting the hierarchy.

Law of Demeter

Don't Talk to Strangers

A method should only call methods on: itself, its parameters, objects it creates, or its direct fields.

Bad: a.getB().getC().doThing()
Good: a.doThing() — A handles the chain internally.

Long chains expose internal structure, creating fragile coupling.

Code Quality

Common Code Smells

Long Method: does too much — extract smaller functions
Large Class: too many responsibilities — split by SRP
Duplicate Code: extract to shared function (DRY)
Feature Envy: method uses another class's data more than its own
Primitive Obsession: use domain objects instead of raw strings/ints

Practice

20 Flashcards

Card 1 / 20 Score: 0 / 0
Question

Answer

Space flip  ·  → next  ·  ← prev  ·  G got it  ·  R review

Your Score
0 / 20

← Back to Catalog Algo3DVerse · Software Design Study Guide Start Lessons →