All subjects.NET · 25 questions · 4 junior / 14 mid / 7 senior

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 quiz25 questions in the bank · 10 per round
Level
Question type
Mode

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.

  1. juniorConcepts

    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.

  2. juniorConcepts

    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.

  3. seniorFind the bug

    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.

  4. midConcepts

    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().

  5. midConcepts

    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.

  6. midConcepts

    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().

  7. midConcepts

    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.

  8. midConcepts

    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.

  9. midConcepts

    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.

  10. seniorConcepts

    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.

More subjects

Need software for your business instead? I'm an AI automation & full-stack developer — see what I build.

Chat on WhatsApp