SOLID & Design Patterns Interview

Anti-Patterns, Refactoring, DI Lifetimes & Senior Design Scenarios

Questions 126-150: Anti-Patterns, Refactoring, DI Lifetimes & Senior Design Scenarios.

25 Questions Filter by level

Interview questions

Open a question for the full answer, code and interview guidance.

25 Results
126
SeniorAdvanced

What is the Service Locator anti-pattern?

Service Locator lets a class obtain dependencies from a global or ambient container instead of declaring them explicitly. This hides what the class requires and can move dependency errors from construction time to runtime.

127
SeniorAdvanced

What is the Spaghetti Code anti-pattern?

Spaghetti Code describes software with tangled control flow, unclear responsibilities, and dependencies that make changes difficult to predict. It often develops through repeated patches without maintaining boundaries or abstractions.

128
SeniorAdvanced

What is the Golden Hammer anti-pattern?

Golden Hammer is the tendency to use one familiar technology, pattern, or technique for many problems even when it is not a good fit. For example, forcing every application into microservices or using a repository abstraction for every trivial data operation.

129
SeniorAdvanced

What is Premature Optimization?

Premature Optimization means increasing complexity to improve performance before evidence shows that the targeted area is a meaningful bottleneck. It can make code harder to understand while producing little measurable benefit.

130
SeniorAdvanced

What is Premature Abstraction?

Premature Abstraction occurs when developers create generalized interfaces, frameworks, or extension points before they understand the variations the software actually needs. The abstraction can become harder to change than duplicated straightforward code.

131
SeniorAdvanced

What is the YAGNI principle?

YAGNI means You Aren't Gonna Need It. It advises against implementing speculative features or extensibility before there is a real requirement.

132
SeniorAdvanced

What is the DRY principle and when can it be misused?

DRY means Don't Repeat Yourself and is primarily about avoiding duplicated knowledge or business rules. When the same rule changes, it should ideally have one authoritative representation.

133
SeniorAdvanced

What is the KISS principle?

KISS means Keep It Simple. In software design, it encourages choosing the simplest solution that correctly satisfies the requirements and remains understandable.

134
SeniorAdvanced

What is separation of concerns?

Separation of concerns divides software so different responsibilities are handled in appropriate components or layers. For example, controllers handle HTTP concerns, domain objects enforce business rules, and repositories or infrastructure components handle persistence.

135
SeniorAdvanced

What is dependency direction and why does it matter?

Dependency direction describes which modules know about and reference other modules. Stable business policy should generally not depend directly on volatile infrastructure details.

136
SeniorAdvanced

How do you decide whether an interface is necessary?

Create an interface when it represents a meaningful abstraction, multiple implementations are expected or present, a boundary must be inverted, or tests need to replace an external collaborator. Do not create interfaces mechanically for every class.

137
SeniorAdvanced

When should inheritance be replaced with composition?

Prefer composition when behavior needs to vary independently, be combined dynamically, or avoid a fragile inheritance hierarchy. Inheritance is appropriate when there is a genuine substitutable is-a relationship and the base contract is stable.

138
SeniorAdvanced

What is the Fragile Base Class problem?

The Fragile Base Class problem occurs when changes to a base class unexpectedly break subclasses that depend on its behavior or implementation details. The risk grows with deep hierarchies and poorly defined extension points.

139
SeniorAdvanced

How does Liskov Substitution influence inheritance design?

Liskov Substitution requires that code using a base abstraction continue to behave correctly when a subtype is supplied. A subtype should preserve the expectations, invariants, and meaningful behavior of the base contract.

140
SeniorAdvanced

How can design patterns improve testability?

Patterns can improve testability when they isolate side effects and introduce meaningful seams. Strategy can make algorithms replaceable, Adapter can isolate external APIs, and Dependency Injection can supply test doubles for infrastructure collaborators.

141
SeniorAdvanced

What design considerations apply to thread-safe singleton services?

A singleton service is shared across concurrent requests, so mutable instance state must be safe for concurrent access. Prefer stateless or immutable singleton services whenever possible.

142
SeniorAdvanced

What is a Scoped service in ASP.NET Core and when is it appropriate?

A scoped service has one instance per dependency-injection scope. In an ASP.NET Core web application, a request normally creates one scope, so scoped services are commonly used for request-oriented work and EF Core DbContext instances.

143
SeniorAdvanced

What is the difference between Transient, Scoped, and Singleton DI lifetimes?

Transient creates a new instance whenever the service is resolved. Scoped reuses one instance within a scope, typically one HTTP request. Singleton reuses one instance for the application's container lifetime.

144
SeniorAdvanced

How would you design a payment integration that supports multiple providers?

Define a provider abstraction around the payment capability required by the application, implement adapters for each external provider, and select the correct implementation using configuration or a factory/strategy.

145
SeniorAdvanced

How would you design notification delivery for Email, SMS, and Push?

Model notification channels behind a focused abstraction or Strategy implementations. Select one or several channels based on user preferences and business rules. Keep transport-specific concerns inside each implementation.

146
SeniorAdvanced

How would you refactor a large switch statement that selects behavior by type?

First determine whether the switch represents genuinely varying behavior. If new cases are added frequently and each case contains substantial logic, Strategy or polymorphism can move each behavior into a focused implementation.

147
SeniorAdvanced

How would you prevent controllers from becoming too large?

Keep controllers focused on HTTP concerns: receiving input, invoking an application use case, and translating the result into an HTTP or view response. Move business rules to domain/application components and data access to repositories or query services where appropriate.

148
SeniorAdvanced

How do you recognize over-engineering in a design?

Over-engineering often appears as many abstractions with no demonstrated variation, excessive indirection for simple operations, infrastructure chosen for hypothetical scale, or patterns that make a small feature difficult to trace.

149
SeniorAdvanced

How should a senior developer choose a design pattern during an interview?

Start by describing the problem, constraints, expected changes, and failure modes. Then explain a simple baseline design and introduce a pattern only when its intent matches a real pressure in the problem.

150
SeniorAdvanced

What are the most important principles for maintainable .NET application design?

Maintainable .NET applications keep responsibilities cohesive, dependencies explicit, domain rules protected, and infrastructure concerns separated from core policies. They use abstractions where they create a real boundary and keep simpler code where additional indirection provides no benefit.