CS FundamentalsHardProduct-company design interview
Which form of dependency injection makes required dependencies explicit and allows the object to be immutable and fully initialised as soon as it is created?
- A. Setter injection
- B. Service-locator lookup inside methods
- C. Field injection by reflection
- D. Constructor injection
Correct answer: D. Constructor injection
With constructor injection an object cannot exist without its dependencies, and fields can be final. Setter injection suits optional dependencies; a service locator hides dependencies again.
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
- A message broker delivers each message at least once, so consumers sometimes see duplicates (for example after a crash before an ack). A…
- Match the delivery guarantee. P: the consumer acks a message before processing it. Q: the consumer acks only after processing succeeds. R…
- In CQRS, what is separated, and what is a typical consequence?
- A method has cyclomatic complexity 25. Which conclusion is most reasonable?
- A team writes acceptance criteria as 'Given a cart worth ₹900, When the user applies coupon SAVE10, Then the total is ₹810', and automates…
- A codebase reports 100% line coverage, but the mutation score is only 20%. What is the most likely explanation?