ProgrammingHardGATE CS · Product-company placement

OrderService creates new MySqlRepository() inside its own constructor. It is refactored to receive a Repository interface through its constructor, so tests can pass a fake. Which SOLID principle does this apply?

  1. A. Dependency Inversion Principle
  2. B. Single Responsibility Principle
  3. C. Liskov Substitution Principle
  4. D. Interface Segregation Principle

Correct answer: A. Dependency Inversion Principle

High-level code should depend on abstractions, not concrete low-level classes; injecting a Repository interface inverts that dependency and makes the service testable.

More OOP with C++ and Java questions

Exams that ask this topic