CS FundamentalsHardCognizant · Capgemini pattern

A ReportService creates a new MySqlDatabase() directly inside its constructor. Refactoring it to receive a Database interface through its constructor follows which principle?

  1. A. Dependency Inversion Principle
  2. B. Liskov Substitution Principle
  3. C. Open/Closed Principle only
  4. D. Law of Demeter

Correct answer: A. Dependency Inversion Principle

DIP: high-level modules should depend on abstractions, not concrete low-level classes. Injecting a Database interface (dependency injection) lets any implementation be plugged in, including test doubles.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic