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?
- A. Composite
- B. Iterator
- C. Proxy
- 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.
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
- A text editor needs multi-level undo and redo, and also wants to queue and log user actions such as 'insert text' or 'delete line'. Which…
- A vending machine's behaviour for insertCoin() and selectItem() differs completely in the states Idle, HasCoin, Dispensing and SoldOut…
- A report class defines generate() as: fetchData(); format(); export(). Subclasses PdfReport and CsvReport override only format() and…
- An app must create a consistent family of UI widgets (Button, Checkbox, Menu) for either a Light or a Dark theme, never mixing a Light…
- A game renders 1,000,000 trees. Each tree object stores mesh and texture data (about 2 MB, the same for every oak) plus its own x, y…
- An editor must save snapshots of a document's internal state so it can be restored later, without exposing the document's private fields…