SOLID & Design Patterns Interview Question #125

What is the God Object anti-pattern and how do you refactor it?

Architectural Patterns, Application Boundaries & Distributed Design Patterns Senior Advanced

Quick Interview Answer

A God Object is a class that accumulates too many responsibilities, dependencies, and reasons to change. It often knows about persistence, validation, calculations, external services, formatting, and workflow coordination at the same time.

Detailed Explanation

A God Object is a class that accumulates too many responsibilities, dependencies, and reasons to change. It often knows about persistence, validation, calculations, external services, formatting, and workflow coordination at the same time.

Refactor by identifying cohesive responsibilities and extracting components around meaningful boundaries. Move domain rules to domain objects or focused services, infrastructure work behind appropriate abstractions, and cross-cutting behavior to middleware, decorators, or pipelines. Refactor incrementally with tests rather than splitting solely by class size.

Code Example

// Before
OrderManager
  -> Validate()
  -> CalculatePrice()
  -> Save()
  -> SendEmail()
  -> ExportPdf()
  -> WriteAudit()

// After
OrderService
  -> IOrderValidator
  -> IPricingPolicy
  -> IOrderRepository
  -> INotificationService
  -> IOrderDocumentGenerator