CS FundamentalsHardProduct-company placement
A class gets its dependencies by calling ServiceLocator.get('Mailer') inside its methods, instead of receiving them through its constructor. What is the main drawback compared with dependency injection?
- A. Each call needs run-time reflection, so the code can no longer be compiled ahead of time
- B. Needs are hidden in method bodies, and tests must configure the global locator
- C. It creates a new Mailer on every call, so shared state between calls becomes impossible
- D. It blocks swapping in a fake Mailer, since the locator only ever returns real objects
Correct answer: B. Needs are hidden in method bodies, and tests must configure the global locator
A service locator still decouples from concrete classes and fakes can be registered, but every class quietly depends on the locator and its real needs show up only at run time. Constructor injection makes them explicit.
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
- In a layered application, which pairing of the Repository and Unit of Work patterns is correct?
- How many of these statements about event sourcing are correct? 1. The append-only log of domain events is the source of truth, and current…
- Match each anti-pattern with its description. P. Golden hammer Q. Lava flow R. God object S. Cargo cult 1. One class knows and does far…
- A release burndown has stayed almost flat for three sprints, yet the team's velocity has been a steady 30 points per sprint. Which chart…
- A work item spent 4 days waiting for development, 2 days in development, 5 days waiting for review, 0.5 day in review, 3 days waiting for…
- How many of these statements about Git submodules are correct? 1. A plain git clone of the superproject leaves submodule directories empty…