CS FundamentalsModerateTCS Digital · Infosys

A file-manager must compute the total size of a folder, where a folder may contain files and other folders, and client code should call size() the same way on either. Which pattern applies?

  1. A. Composite
  2. B. Iterator
  3. C. Proxy
  4. D. Flyweight

Correct answer: A. Composite

Composite builds a part-whole tree where leaves (files) and composites (folders) share an interface; a folder's size() simply sums its children's size(). Iterator only traverses; it doesn't make leaves and containers uniform.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic