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?
- A. Dependency Inversion Principle
- B. Single Responsibility Principle
- C. Liskov Substitution Principle
- 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
- An interface Machine declares print(), scan() and fax(). A SimplePrinter class implements it and has to make scan() and fax() throw…
- A GUI toolkit must create a matching Button, Checkbox and Window for either a Windows or a Mac theme, guaranteeing that all widgets come…
- In C++11 and later, which statement about this 'Meyers singleton' is correct? cpp Logger& instance() { static Logger log; return log; }
- How many of these are resolved at COMPILE time in C++? (i) Which function body a call to a non-virtual member function through a…
- What is printed? java String b = "java"; String a = "ja" + "va"; String c = "ja"; String d = c + "va"; final String e = "ja"; String f = e…
- What is printed? java class A { void f(Object o) { System.out.print("AO "); } void f(String s) { System.out.print("AS "); } } class B…