CS FundamentalsHardGATE CS · TCS NQT Prime · Product Company SDE
A reporting class depends directly on a concrete EmailSender class to send alerts. A new requirement asks for alerts to optionally go via SMS instead. Applying SOLID principles, what is the recommended refactor?
- A. Add an if-statement inside EmailSender that checks whether SMS was requested
- B. Copy the entire reporting class and hardcode SMS logic into the duplicate
- C. Introduce an AlertSender abstraction that both EmailSender and a new SmsSender implement, and have the reporting class depend on that abstraction instead of the concrete EmailSender
- D. Make the reporting class extend both EmailSender and SmsSender simultaneously
Correct answer: C. Introduce an AlertSender abstraction that both EmailSender and a new SmsSender implement, and have the reporting class depend on that abstraction instead of the concrete EmailSender
Introducing a shared abstraction that concrete senders implement, and depending on that abstraction, follows both Dependency Inversion and Open/Closed: new sender types can be added without modifying the reporting class or existing senders.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- Two components with availability 97.0% and 90.0% are connected in series (the system works only if both are up). What is the system's…
- A Type 2 (hosted) hypervisor, such as VirtualBox or VMware Workstation, differs from a Type 1 (bare-metal) hypervisor such as VMware ESXi…
- What does git commit --amend do?
- For a organic mode project with Basic COCOMO effort E = 55.8 person-months, the development time formula is D = 2.5 × E^0.38 months. What…
- A third-party payment gateway's SDK exposes an interface completely incompatible with the shape your application's PaymentProcessor…
- A microservice architecture replaces a single large monolith with many small, independently deployable services. Which of these is a…