CS FundamentalsHardProduct-company placement
Assertion (A): Classes that call a Singleton through its global getInstance() are harder to unit-test. Reason (R): The dependency is hidden inside the code rather than passed in, so a test cannot easily substitute a fake.
- A. Both A and R are true and R explains A
- B. Both A and R are true, but R does not explain A
- C. A is true but R is false
- D. A is false but R is true
Correct answer: A. Both A and R are true and R explains A
A hard-wired global lookup acts like hidden global state; tests share it and cannot inject a test double without extra hooks. Passing the instance in (dependency injection) fixes testability while keeping a single instance.
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 the 2020 Scrum Guide each artifact has a commitment. Which pairing is correct?
- Midway through a sprint, a market change makes the Sprint Goal obsolete. According to the Scrum Guide, who can cancel the sprint?
- At the end of a sprint, one backlog item is coded but its automated tests, required by the Definition of Done, are not written. What does…
- A sprint commitment had stories of 8, 5, 5, 3 and 3 points. At the sprint's end the 8, one 5 and both 3s meet the Definition of Done; the…
- Mid-sprint, the Product Owner asks the Developers to also add a small new item. The Sprint Goal is not at risk. What does Scrum allow?
- For a one-month sprint the Scrum Guide sets maximum timeboxes of 8 hours for Sprint Planning, 4 hours for the Sprint Review and 3 hours…