Design patterns·Wrapping and composing
a folder and a file answer the same size method, so the code that totals them never checks which it has.
Composite pattern
Also calledcomposite, tree of parts, part-whole hierarchy
Treating a group of objects and a single object through the same interface, so a tree can be handled without the caller distinguishing leaves from branches. Files and folders, UI elements and containers, and nested validation rules are the everyday instances. Its awkward corner is operations that only make sense on one kind — adding a child to a leaf — which forces either an interface that lies or a caller that checks after all.