All challenges
Multiple ChoiceIntermediate 45s

Decorator vs inheritance

You need logging, retry, and caching wrapped around an HTTP client in any combination. Why is Decorator usually better than subclassing?
Options
  1. 1A subclass cannot call the super methods of its parent. That makes subclassing unsafe.
  2. 2Decorator removes the need for a wrapped interface. No shared interface is required between the types.
  3. 3Decorator composes behaviors at runtime without a combinatorial subclass explosion
  4. 4Subclasses always carry higher memory overhead. Each subclass copy duplicates its parent state.

Think you can answer under pressure?

Get matched and answer live questions in 3-minute 1v1 battles. Elo ranking, badge tiers and bragging rights on the line.

Play this in a 3-minute battle