SOLID & OOP Principles (50 Qs)•Part 3: Enterprise Architecture, Package Design & Enforcement (25 - 35)
Refactoring God Classes to SRP: Facades and Delegation.
senior LevelSystem Design
In Simple Words:
Refactoring a 5,000-line monolithic UserManager class:
- Identify cohesive clusters of methods:
- Auth & Passwords -> Extract to
AuthenticationService. - Email Notifications -> Extract to
UserEmailNotifier. - Profile Billing -> Extract to
UserSubscriptionService.
- Auth & Passwords -> Extract to
- Convert the original
UserManagerinto a lightweight Facade that delegates calls to the new specialized services. - Migrate caller code over time to depend directly on the specialized services, and eventually retire the facade.