skip to content

Design Principles

The rules that decide whether code stays changeable: SOLID, GRASP, and the everyday heuristics like DRY, cohesion and coupling. They come up constantly in interviews because they are the vocabulary reviewers use to explain why a design feels wrong.

part ofSoftware design & architectureoverview, primer and where to startread it →
on this pageshow

explore

questions

196 · 4 sections

What does the Dependency Inversion Principle (DIP) state, and what exactly is being "inverted"?

level: juniorimportance: must knowfreq 78%
basics
~20 s

DIP says important policy code must not depend on low-level detail code; both depend on an abstraction (an interface). What gets inverted is the source-code dependency: the detail now points at the abstraction instead of the policy pointing at the detail.

open as a page

What does the Interface Segregation Principle (ISP) state, and what problem is it meant to prevent?

level: juniorimportance: must knowfreq 78%
basics
~20 s

ISP — the "I" in SOLID — says no caller should be forced to depend on operations it never uses. Instead of one large interface with many unrelated methods, define several small ones, each matching what a particular caller actually needs.

open as a page

What is the Liskov Substitution Principle (the "L" in SOLID), and what does it require of a subtype?

level: juniorimportance: must knowfreq 85%
basics
~20 s

If type S is a subtype of type T, code written against T must keep working correctly when handed an S. A subtype must honour the promises its supertype made — not just match method names.

open as a page

What does the Open/Closed Principle (the "O" in SOLID) mean by "open for extension, closed for modification"?

level: juniorimportance: must knowfreq 82%
basics
~10 s

You should be able to add new behavior to a module by adding new code (a new class or plug-in), without editing and re-testing the existing, already-working code.

open as a page

What does the Single Responsibility Principle (the "S" in SOLID) state, and what does "one reason to change" actually mean?

level: juniorimportance: must knowfreq 88%
basics
~20 s

SRP says a class or module should do one job, so only one kind of change forces you to edit it. If both a reporting change and a tax-rule change hit the same class, it has two responsibilities.

open as a page

In software design, what do the terms "cohesion" and "coupling" mean, and what is the standard rule of thumb about them?

level: juniorimportance: must knowfreq 88%
basics
~10 s

Cohesion is how strongly the things inside one module belong together. Coupling is how much one module depends on another. The rule: aim for high cohesion inside modules and low coupling between them.

open as a page

What does the design guideline "favor composition over inheritance" actually mean, and what is the difference between the two techniques?

level: juniorimportance: must knowfreq 78%
basics
~20 s

Inheritance reuses code by making a new type a subtype of an existing one ("is-a"). Composition reuses code by holding another object as a field and calling it ("has-a"). Prefer composition: it couples types less and can change at runtime.

open as a page

In software design, what is the difference between abstraction and indirection, and why is it said that every abstraction introduces indirection but not every indirection is an abstraction?

level: juniorimportance: must knowfreq 55%
basics
~20 s

Abstraction hides detail behind a simpler idea you can reason about, like 'send a payment'. Indirection just means going through something in between instead of calling the thing directly. Abstractions use indirection, but a pass-through wrapper that hides nothing is only indirection.

open as a page

What is Command-Query Separation (CQS), and how do you classify a method as a command or a query?

level: juniorimportance: must knowfreq 58%
basics
~10 s

CQS says every method should either change state (a command, returning nothing) or return information (a query, changing nothing) — never both. Put differently: asking a question must not change the answer.

open as a page

What does the "fail fast" design principle mean, and why is stopping at the moment invalid state is detected usually better than letting execution continue?

level: juniorimportance: must knowfreq 65%
basics
~20 s

Fail fast means checking for invalid input or state right where it appears and stopping immediately with a clear error, instead of continuing with bad data that causes a confusing failure much later somewhere else.

open as a page

What does the Acyclic Dependencies Principle (ADP) state, and which team failure mode — nicknamed "the morning-after syndrome" — does it prevent?

level: juniorimportance: must knowfreq 55%
basics
~20 s

ADP says: allow no cycles in the dependency graph between components (releasable units like packages, modules, or libraries). Cycles cause the "morning-after syndrome": someone edits code you depend on overnight, your work breaks, and because dependencies loop, nobody can ever stabilize.

open as a page

What does the Common Closure Principle (CCP) of component design state, and what problem does it prevent?

level: juniorimportance: must knowfreq 45%
basics
~20 s

CCP says: put into one component the classes that change for the same reasons and at the same times. Then a typical change touches one component instead of many, so you rebuild, retest and redeploy less.

open as a page

What does the Common Reuse Principle (CRP), one of Robert C. Martin's component-cohesion principles, state, and what problem is it meant to prevent?

level: juniorimportance: must knowfreq 40%
basics
~10 s

CRP says classes that are used together should be packaged together, and classes that are not used together should not be. It keeps consumers from depending on, rebuilding, and redeploying code they never use.

open as a page

In component-level design metrics, what do Instability (I) and Abstractness (A) measure, and how is each computed?

level: juniorimportance: must knowfreq 42%
basics
~20 s

Instability I = outgoing dependencies / (outgoing + incoming). It says how easily a component can be forced to change. Abstractness A = abstract types / all types. It says how much of the component is interfaces rather than concrete code. Both run 0 to 1.

open as a page

What does the Reuse/Release Equivalence Principle (REP) state, and what does it require of a reusable component?

level: juniorimportance: must knowfreq 38%
basics
~20 s

REP says the granule of reuse is the granule of release: the unit you reuse must be the unit you release. A component has to be published as a versioned whole, with a version number and release notes, so consumers depend on a specific version instead of copying files.

open as a page

In the GRASP set of design principles, what does the Controller principle say about who should receive a system input event (such as a button click or an incoming HTTP request), and why?

level: juniorimportance: must knowfreq 72%
basics
~20 s

GRASP Controller says: don't let the UI widget itself do the work. Give the event to a separate non-UI object — a controller — that coordinates the domain objects and returns a result. This keeps screen code and business rules apart.

open as a page

What does the GRASP "Creator" principle say about deciding which class should be responsible for creating instances of another class?

level: juniorimportance: must knowfreq 55%
basics
~20 s

Creator says: give the job of making a new object to a class that already aggregates, contains, records, closely uses, or holds the data needed to build it. That class already knows about it, so creating it adds no new coupling.

open as a page

In the GRASP set of responsibility-assignment principles, what does High Cohesion mean, and what concrete problems does a low-cohesion class cause?

level: juniorimportance: must knowfreq 68%
basics
~20 s

Cohesion is how well everything inside one class belongs together. High Cohesion says a class should keep a small set of closely related responsibilities, so it stays easy to name, understand, change, test and reuse.

open as a page

In the GRASP set of object-oriented design principles, what does the Indirection principle say, and what problem does it solve?

level: juniorimportance: must knowfreq 55%
basics
~10 s

Indirection says: when two components would otherwise be wired directly together, put a third object between them to mediate. Neither side knows the other, so each can change or be replaced independently.

open as a page

What does the GRASP principle "Information Expert" say about where a responsibility should live, and why?

level: juniorimportance: must knowfreq 62%
basics
~20 s

Give a job to the object that already holds the data needed to do it. If an order knows its line items, the order should compute its own total, instead of another class pulling the items out first.

open as a page