CS FundamentalsHardProduct-company design interview
A Customer may or may not have a discount policy. Instead of writing `if policy is not None: total = policy.apply(total)` everywhere, the code uses a NoDiscount class whose apply() returns the total unchanged. Which pattern is this?
- A. Proxy
- B. Strategy only, with no special name
- C. Null Object
- D. Singleton
Correct answer: C. Null Object
A Null Object is a do-nothing implementation of the interface that removes repeated null checks; it is often combined with Strategy, as here.
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 form of dependency injection makes required dependencies explicit and allows the object to be immutable and fully initialised as…
- 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…