CS FundamentalsHardGATE CS · TCS NQT Prime · Product Company SDE
A high-level OrderService class directly instantiates and depends on a concrete MySqlDatabase class. What does the Dependency Inversion Principle recommend instead?
- A. Both OrderService and MySqlDatabase should depend on a shared abstraction (e.g. a Database interface), with OrderService depending on that interface rather than the concrete class directly
- B. High-level modules should never be allowed to call any low-level module at all, under any abstraction
- C. MySqlDatabase should directly extend OrderService
- D. OrderService should be merged into the same class as MySqlDatabase
Correct answer: A. Both OrderService and MySqlDatabase should depend on a shared abstraction (e.g. a Database interface), with OrderService depending on that interface rather than the concrete class directly
DIP says high-level modules should not depend on low-level modules directly; both should depend on abstractions, which is what lets OrderService later swap in a different database implementation without being rewritten.
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
- A team must build a system whose requirements are well understood and unlikely to change, with a fixed, firm deadline and no room for…
- During Sprint Planning, who decides how MANY Product Backlog items the Development Team commits to for the upcoming Sprint?
- A Scrum team completed 34, 22, 16, 26, 36 story points in its last 5 sprints. The remaining backlog is 214 points. Using average velocity…
- A PERT activity has optimistic time 5 days, most likely time 6 days and pessimistic time 9 days. What is its expected duration, Te = (O +…
- A PERT activity has optimistic time 5 days, most likely time 11 days and pessimistic time 13 days. What is its expected duration, Te = (O…
- A CI pipeline's test stage takes 45 minutes to run on every commit, significantly slowing developer feedback. Which of these is a…