A notification class has growing email, SMS, and push conditionals. How would you refactor it?
Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Saved automatically
Model Answer & Deep-Dive Explanation
Identify the common send operation and introduce a notification-channel interface with separate email, SMS, and push implementations. Inject the selected channel into the application service and keep routing rules in one place. Each implementation handles its own provider errors and configuration. Add contract tests for shared expectations and focused tests for each channel. This makes adding a channel less likely to break existing ones. Avoid building a large plugin framework when three small implementations and straightforward composition are sufficient.
Related Questions in Software Engineering & OOP
Explain the SOLID Principles of Object-Oriented Software Engineering with Examples
Intermediate level • 623 views
Explain ACID properties in relational databases and how different Transaction Isolation Levels prevent concurrency anomalies.
Intermediate level • 152 views
How does encapsulation protect an object’s rules? Explain using a bank account.
Easy level • 5 views
How do abstraction and inheritance solve different problems?
Easy level • 5 views
How would you evolve a public API without breaking existing clients?
Medium level • 5 views