SOLID & Design Patterns Interview Questions and Answers
SOLID principles and design pattern interview questions — the Repository and Unit of Work patterns, Factory, Strategy, Singleton, Dependency Inversion, CQRS and when not to use a pattern.
- 01 What is the Open/Closed Principle, with an example? A class should be open for extension but closed for modification — you add new behaviour by adding new code (a new…
- 02 What is the Liskov Substitution Principle? LSP says a subtype must be usable anywhere its base type is expected, without the caller noticing. A subclass can't…
- 03 What is the Interface Segregation Principle? No client should be forced to depend on methods it doesn't use. Prefer several small, focused (“role”) interfaces over…
- 04 What is the Decorator pattern? Decorator wraps an object in another object that implements the same interface, adding behaviour before/after…
- 05 What is the Adapter pattern? Adapter converts one interface into another that a client expects. You have a third-party library (or legacy class)…
- 06 What is the Observer pattern, and how does C# support it? Observer defines a one-to-many dependency: when a subject changes state, all its registered observers are notified…
- 07 What is the Facade pattern? Facade provides a single, simple interface over a complex subsystem of many classes. The client calls…
- 08 What is the Builder pattern? Builder separates the construction of a complex object from its representation, building it step by step — usually…
- 09 What is Domain-Driven Design (DDD) at a high level? DDD is an approach to modelling complex software around the business domain. Its core ideas: a ubiquitous language…
- 10 What is Clean Architecture / Onion Architecture? Clean/Onion architecture organises code in concentric layers — Domain (entities, rules) at the centre, Application…
- 11 What is a value object, and how is it different from an entity? An entity has an identity that persists through changes — a Customer is the same customer even if their name changes.…
- 12 What is a pure function, and why does it matter? A pure function's output depends only on its inputs, and it has no side effects — no I/O, no mutation of external…
- 13 What do YAGNI, DRY and KISS mean, and can they conflict? YAGNI — don't build what you only think you'll need. DRY — every piece of knowledge should have one authoritative…
- 14 What are the SOLID principles? SOLID is five object-oriented design principles: Single Responsibility (a class has one reason to change), Open/Closed…
- 15 What is the Single Responsibility Principle, with an example? A class should have one responsibility — one reason to change. If a class does data access and business rules and…
- 16 What is the Dependency Inversion Principle, and how is it different from dependency injection? The Dependency Inversion Principle says: high-level modules should not depend on low-level modules — both should…
- 17 What is the Repository pattern, and do you need it with EF Core? The Repository pattern puts a collection-like abstraction (IOrderRepository with Add, GetById, Find) between your…
- 18 What is the Unit of Work pattern? Unit of Work tracks every change made during a business operation and commits them together in a single transaction…
- 19 What is the Factory pattern, and when would you use it? A Factory centralises object creation so callers ask for what they need, not how to build it. Use it when construction…
- 20 What is the Strategy pattern? Strategy defines a family of interchangeable algorithms behind a common interface and lets you pick one at run time.…
- 21 What is the Singleton pattern, and what are its downsides? Singleton ensures a class has exactly one instance with a global access point. The classic implementation is a private…
- 22 What is CQRS? CQRS (Command Query Responsibility Segregation) splits the model that changes data (commands) from the model that…
- 23 What is the Mediator pattern (and MediatR)? Mediator routes messages between components so they don't reference each other directly — they only know the mediator.…
- 24 When should you NOT use a design pattern? Don't add a pattern for a problem you don't have yet. Patterns trade simplicity for flexibility; if the flexibility…
- 25 What is the difference between an entity and a value object in domain modelling? An entity has a distinct identity that persists through changes — a Customer is the same customer even after they…
- 26 What is the difference between coupling and cohesion? Coupling is how much one module depends on the internals of another — you want it loose. Cohesion is how focused a…
- 27 What is the strangler fig pattern for legacy migration? Instead of a risky big-bang rewrite, you put a routing facade in front of the legacy system and incrementally replace…
- 28 What is the specification pattern? The specification pattern packages a business rule or query predicate as an object with an IsSatisfiedBy(entity)…
- 29 What is event sourcing? Instead of storing an entity's current state and overwriting it on every change, event sourcing stores the full…
- 30 What is hexagonal architecture (ports and adapters)? Hexagonal architecture puts the domain/application logic at the centre, exposed through ports (interfaces it defines —…
- 31 What is a domain event, and how is it different from an integration event? A domain event — something that happened inside the domain that other parts of the same process might care about…
- 32 What is the outbox pattern, and what problem does it solve? Writing to your database and publishing a message are two separate systems — if the process crashes between them, you…
- 33 What are the trade-offs between a monolith and microservices? A monolith is one deployable — simple to build, test, deploy and debug; scales as a unit. Microservices are many…
- 34 What is eventual consistency, and when is it acceptable? Eventual consistency means after a change, different parts of the system converge to the same value eventually, but…
- 35 You've inherited a large legacy codebase with no tests and a bug to fix. How do you proceed? Reproduce the bug and understand its blast radius before touching anything. Pin the current behaviour with a…
- 36 Two services need the same data. Do you share a database, call an API, or replicate? Prefer a single owner for each piece of data. If service B needs service A's data: a synchronous API call when B needs…
- 37 You have two reasonable ways to build a feature. How do you decide? Name the forces that matter here — time-to-ship, change frequency, team familiarity, performance, operational cost —…
No questions match those filters
Try removing a filter or .
About these SOLID & Design Patterns questions
Architecture rounds and senior .NET interviews lean on SOLID and a handful of patterns. Interviewers are not checking whether you memorised the Gang of Four — they want to hear you explain a principle in your own words, give a real example of applying it, and say when a pattern is not worth the indirection.
The patterns that come up most in .NET are Repository and Unit of Work (and the debate about whether EF Core already is one), Factory, Strategy, Singleton (and its testability problems), and increasingly CQRS with a mediator. The Dependency Inversion Principle connects straight to the dependency injection questions in the ASP.NET Core section.