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 pageshowhide
explore
- SOLID Principles35 questions
- Single Responsibility Principle5 questions
- Open/Closed Principle6 questions
- Liskov Substitution Principle6 questions
- Interface Segregation Principle6 questions
- Dependency Inversion Principle6 questions
- Applying SOLID6 questions
- Core Design Principles73 questions
- DRY Principle5 questions
- KISS and YAGNI6 questions
- Separation of Concerns5 questions
- Cohesion and Coupling6 questions
- Composition Over Inheritance6 questions
- Encapsulation and Information Hiding5 questions
- Law of Demeter6 questions
- Tell, Don't Ask6 questions
- Command-Query Separation6 questions
- Abstraction and Indirection6 questions
- Principle of Least Astonishment5 questions
- Fail Fast6 questions
- Single Source of Truth5 questions
- Package and Component Principles39 questions
- Reuse/Release Equivalence Principle5 questions
- Common Closure Principle6 questions
- Common Reuse Principle6 questions
- Acyclic Dependencies Principle5 questions
- Stable Dependencies Principle6 questions
- Stable Abstractions Principle5 questions
- Distance from the Main Sequence6 questions
- GRASP Principles49 questions
- Information Expert5 questions
- Creator6 questions
- Controller5 questions
- Low Coupling (GRASP)5 questions
- High Cohesion (GRASP)6 questions
- Polymorphism (GRASP)6 questions
- Pure Fabrication5 questions
- Indirection (GRASP)5 questions
- Protected Variations6 questions
- Backend Developerroleanchors this topic
- Full Stack Developerroleanchors this topic
- Java Backend Developerroleanchors this topic
- Kotlin Backend Developerroleanchors this topic
- Software Design & Architectureskillanchors this topic
- Forward Deployed Engineerrole
- Game Developerrole
- Server-Side Game Developerrole
- Software Architectrole
questions
196 · 4 sectionsWhat does the Dependency Inversion Principle (DIP) state, and what exactly is being "inverted"?
basics
~20 sDIP 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.
What does the Interface Segregation Principle (ISP) state, and what problem is it meant to prevent?
basics
~20 sISP — 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.
What is the Liskov Substitution Principle (the "L" in SOLID), and what does it require of a subtype?
basics
~20 sIf 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.
What does the Open/Closed Principle (the "O" in SOLID) mean by "open for extension, closed for modification"?
basics
~10 sYou 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.
What does the Single Responsibility Principle (the "S" in SOLID) state, and what does "one reason to change" actually mean?
basics
~20 sSRP 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.
In software design, what do the terms "cohesion" and "coupling" mean, and what is the standard rule of thumb about them?
basics
~10 sCohesion 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.
What does the design guideline "favor composition over inheritance" actually mean, and what is the difference between the two techniques?
basics
~20 sInheritance 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.
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?
basics
~20 sAbstraction 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.
What is Command-Query Separation (CQS), and how do you classify a method as a command or a query?
basics
~10 sCQS 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.
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?
basics
~20 sFail 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.
What does the Acyclic Dependencies Principle (ADP) state, and which team failure mode — nicknamed "the morning-after syndrome" — does it prevent?
basics
~20 sADP 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.
What does the Common Closure Principle (CCP) of component design state, and what problem does it prevent?
basics
~20 sCCP 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.
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?
basics
~10 sCRP 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.
In component-level design metrics, what do Instability (I) and Abstractness (A) measure, and how is each computed?
basics
~20 sInstability 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.
What does the Reuse/Release Equivalence Principle (REP) state, and what does it require of a reusable component?
basics
~20 sREP 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.
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?
basics
~20 sGRASP 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.
What does the GRASP "Creator" principle say about deciding which class should be responsible for creating instances of another class?
basics
~20 sCreator 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.
In the GRASP set of responsibility-assignment principles, what does High Cohesion mean, and what concrete problems does a low-cohesion class cause?
basics
~20 sCohesion 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.
In the GRASP set of object-oriented design principles, what does the Indirection principle say, and what problem does it solve?
basics
~10 sIndirection 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.
What does the GRASP principle "Information Expert" say about where a responsibility should live, and why?
basics
~20 sGive 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.