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?
- A. Dependency Inversion Principle
- B. Liskov Substitution Principle
- C. Open/Closed Principle only
- 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.
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
- Which HTTP method is NOT idempotent by definition?
- A logged-in user with a valid token calls an admin-only API endpoint. Which status code should the server return?
- In the IaaS model (for example a plain cloud virtual machine), which of these is the customer's responsibility rather than the provider's?
- A Scrum team's last three sprints delivered 28, 32 and 30 story points. 240 points remain in the backlog and sprints are 2 weeks long…
- Using basic COCOMO for an organic project (E = 2.4 × KLOC^1.05 person-months), what is the estimated effort for a 32 KLOC project?
- For the code if (x > 0) { y = 1; } followed by print(y), a single test with x = 5 is run. What coverage does it achieve?