SOLID & Design Patterns Interview Question #100

How would you refactor a large ASP.NET Core service that violates multiple SOLID principles?

DDD Boundaries, Resilience, Caching & Practical ASP.NET Core Design Mid-Level Intermediate

Quick Interview Answer

First identify responsibilities and reasons for change rather than splitting the class only by line count. Separate business rules, persistence, external integrations, notifications, and cross-cutting concerns into cohesive components with clear boundaries.

Detailed Explanation

First identify responsibilities and reasons for change rather than splitting the class only by line count. Separate business rules, persistence, external integrations, notifications, and cross-cutting concerns into cohesive components with clear boundaries.

Introduce abstractions where multiple implementations, external dependencies, or test seams provide value. Move domain rules into appropriate domain objects or focused services, use constructor injection, and replace growing conditionals with patterns such as Strategy only when behavior genuinely varies.

Refactor incrementally with tests around existing behavior. Avoid replacing one large class with dozens of trivial interfaces that merely move complexity without improving the design.

Code Example

// Before:
OrderManager
  -> validates
  -> calculates price
  -> saves to SQL
  -> sends email
  -> writes audit log

// After:
OrderService
  -> IOrderValidator
  -> IPricingStrategy
  -> IOrderRepository
  -> INotificationService

// Cross-cutting logging can live in
// middleware, decorators, or pipeline behavior.