SOLID & Design Patterns quiz and interview questions
Senior interviews move from "what does this code do" to "how would you design it". This quiz covers the SOLID principles and the patterns you'll meet in real .NET code — singleton, factory, repository, strategy, decorator and more — with small C# examples.
SOLID & Design Patterns: key concepts
- SOLID
- Single responsibility, Open/closed, Liskov substitution, Interface segregation, Dependency inversion — rules that keep code easy to change.
- Creational patterns
- Singleton (one instance), Factory (create objects without naming concrete classes), Builder (assemble complex objects step by step).
- Structural patterns
- Adapter (convert one interface to another), Decorator (wrap an object to add behaviour, e.g. caching or logging).
- Behavioural patterns
- Strategy (swap algorithms at run time), Observer (notify subscribers), Chain of Responsibility (pass a request along a pipeline).
- Data access patterns
- Repository hides data-access details behind an interface; Unit of Work saves a set of changes in one transaction.
- Dependency injection
- Classes receive their dependencies (usually interfaces) through the constructor, so implementations can be swapped and tested.
All 25 SOLID & Design Patterns questions with answers
Try each one first, then open the answer. Making a class test? Use the test maker.
What is a design pattern?
- A. A UI theme
- B. A proven, reusable solution to a common software design problem
- C. A library
- D. A coding style guide
Show answer
B. A proven, reusable solution to a common software design problem — Patterns give names to good solutions, so teams can say "use a strategy here" and mean the same thing.
What does the Singleton pattern guarantee?
- A. Fast code
- B. A class has only one instance, with a global access point
- C. One method per class
- D. One thread
Show answer
B. A class has only one instance, with a global access point — In ASP.NET Core you usually get this with AddSingleton instead of writing the pattern by hand.
What's wrong with this singleton in a multi-threaded app?
public static Logger Instance { get { if (_instance == null) _instance = new Logger(); return _instance; } }- A. Nothing
- B. Two threads can both see null and create two instances — use Lazy<T> or a static readonly field
- C. Properties can't be static
- D. Logger must be sealed
Show answer
B. Two threads can both see null and create two instances — use Lazy<T> or a static readonly field — private static readonly Lazy<Logger> _lazy = new(() => new Logger()); is thread-safe and lazy.
What problem does the Factory pattern solve?
- A. Slow loops
- B. Creating objects without the caller depending on concrete classes
- C. Database access
- D. Thread safety
Show answer
B. Creating objects without the caller depending on concrete classes — PaymentFactory.Create("card") returns an IPayment; the caller never writes new StripePayment().
What does the Repository pattern do?
- A. Stores files in Git
- B. Hides data-access code behind an interface such as IOrderRepository
- C. Caches HTTP responses
- D. Creates singletons
Show answer
B. Hides data-access code behind an interface such as IOrderRepository — Services call _orders.GetById(id) without knowing whether EF, Dapper or an API is underneath — and tests can use a fake.
What does Unit of Work add?
- A. Logging
- B. Groups several changes into one transaction committed together
- C. Retries
- D. Caching
Show answer
B. Groups several changes into one transaction committed together — EF Core's DbContext already acts as a unit of work: everything changed is saved by one SaveChanges().
Card, PayPal and bank transfer payments should be swappable at run time. Which pattern fits?
- A. Singleton
- B. Strategy
- C. Adapter
- D. Builder
Show answer
B. Strategy — Each payment method implements IPaymentStrategy; the checkout picks one at run time instead of a big if/else.
Which pattern do C# events implement?
- A. Factory
- B. Observer
- C. Decorator
- D. Repository
Show answer
B. Observer — Subscribers (+=) are notified when the publisher raises the event — the Observer pattern.
You want to add caching around an existing IProductService without changing it. Which pattern?
- A. Decorator
- B. Singleton
- C. Factory
- D. Observer
Show answer
A. Decorator — CachedProductService wraps the real service, implements the same interface and adds caching.
A third-party SMS library has a different interface from your ISmsSender. Which pattern connects them?
- A. Adapter
- B. Strategy
- C. Builder
- D. Observer
Show answer
A. Adapter — An adapter class implements ISmsSender and translates calls to the library's API.
What does the S in SOLID stand for?
- A. Static
- B. Single Responsibility
- C. Security
- D. Scalability
Show answer
B. Single Responsibility — A class should have one reason to change — e.g. calculating invoices, not also emailing and saving them.
The Interface Segregation Principle recommends…
- A. One big interface for everything
- B. Several small, focused interfaces so classes don't implement methods they don't need
- C. No interfaces
- D. Only abstract classes
Show answer
B. Several small, focused interfaces so classes don't implement methods they don't need — Split IWorker into IWorkable and IFeedable rather than forcing a robot to implement Eat().
When is the Builder pattern useful?
- A. For one-line objects
- B. To construct complex objects step by step with readable code
- C. For singletons
- D. For database access
Show answer
B. To construct complex objects step by step with readable code — new ReportBuilder().WithTitle("Q3").AddChart(c).Build() beats a constructor with ten parameters.
Why is the Service Locator often called an anti-pattern?
- A. It's too fast
- B. It hides a class's dependencies inside its methods, making code harder to understand and test
- C. It can't be used in .NET
- D. It requires XML
Show answer
B. It hides a class's dependencies inside its methods, making code harder to understand and test — With constructor injection, dependencies are visible in the constructor. A locator pulls them from anywhere at run time.
What is CQRS?
- A. A database
- B. Separating commands (writes) from queries (reads), often with different models
- C. A caching library
- D. A testing framework
Show answer
B. Separating commands (writes) from queries (reads), often with different models — Reads can use fast, flattened models while writes go through rich domain logic — useful in larger systems.
ASP.NET Core's middleware pipeline is an example of which pattern?
- A. Singleton
- B. Chain of Responsibility
- C. Adapter
- D. Builder
Show answer
B. Chain of Responsibility — Each middleware handles the request or passes it to the next one in the chain.
Which SOLID principle does this class break?
class Invoice { public decimal Total() { /* ... */ } public void SaveToDatabase() { /* ... */ } public void SendEmail() { /* ... */ } }- A. Liskov Substitution
- B. Single Responsibility
- C. Interface Segregation
- D. None
Show answer
B. Single Responsibility — It calculates, persists and emails — three reasons to change. Move saving to a repository and emailing to a notifier.
Which three groups are the classic (Gang of Four) patterns divided into?
- A. Front end, back end, database
- B. Creational, structural, behavioural
- C. Simple, medium, advanced
- D. MVC, MVP, MVVM
Show answer
B. Creational, structural, behavioural — Creational = how objects are made; structural = how they're combined; behavioural = how they communicate.
What does the Facade pattern do?
- A. Copies objects
- B. Gives a simple interface over a complicated subsystem
- C. Creates one instance
- D. Notifies subscribers
Show answer
B. Gives a simple interface over a complicated subsystem — A CheckoutService.PlaceOrder() call can hide stock, payment, invoice and email steps behind one method.
What is the Prototype pattern?
- A. A first draft of an app
- B. Creating new objects by cloning an existing one
- C. A base class for all objects
- D. A UI mockup
Show answer
B. Creating new objects by cloning an existing one — Useful when building an object from scratch is expensive; records' with-expressions give a similar effect.
When does Abstract Factory help?
- A. Creating one object
- B. Creating families of related objects that must match, like Light or Dark theme buttons, inputs and menus
- C. Caching objects
- D. Logging
Show answer
B. Creating families of related objects that must match, like Light or Dark theme buttons, inputs and menus — Swap the whole factory to switch the family without changing client code.
What does the Command pattern turn a request into?
- A. A string
- B. An object, so it can be queued, logged or undone
- C. A database row
- D. An event
Show answer
B. An object, so it can be queued, logged or undone — Undo/redo stacks and job queues usually store command objects.
What is the main idea of MVVM?
- A. Model–View–Value–Method
- B. The View binds to a ViewModel that exposes data and commands, keeping UI logic testable
- C. It's MVC with two views
- D. Views talk directly to the database
Show answer
B. The View binds to a ViewModel that exposes data and commands, keeping UI logic testable — Common in WPF, MAUI and Blazor-style apps with data binding.
What does the Template Method pattern do?
- A. Generates HTML templates
- B. A base class defines the steps of an algorithm and lets subclasses fill in some steps
- C. Copies a template object
- D. Wraps an object
Show answer
B. A base class defines the steps of an algorithm and lets subclasses fill in some steps — e.g. ReportBase.Generate() calls LoadData(), Format(), Export() — subclasses override Format().
What is Clean (Onion) Architecture's main rule?
- A. Put everything in one project
- B. Dependencies point inward: the domain core knows nothing about the database, UI or frameworks
- C. The UI owns the database
- D. Use microservices
Show answer
B. Dependencies point inward: the domain core knows nothing about the database, UI or frameworks — Infrastructure implements interfaces defined by the core, so business rules stay testable and portable.
More subjects
Need software for your business instead? I'm an AI automation & full-stack developer — see what I build.