CS FundamentalsHardWipro · Accenture pattern

A spreadsheet's Cell objects can contain other Cells (a range), and client code calls cell.getValue() uniformly whether cell is a single number cell or a range of cells, with the range summing its children recursively. Which pattern is this?

  1. A. Bridge
  2. B. Flyweight
  3. C. Composite
  4. D. Decorator

Correct answer: C. Composite

Composite lets clients treat individual objects and compositions of objects (a tree of parts and wholes) uniformly through a shared interface — exactly the single-cell-vs-range-of-cells scenario. Decorator adds behaviour to a single object; it doesn't model part-whole trees.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic