Design patterns Composite pattern


Composite lets clients treat individual objects and compositions of objects uniformly. For example consider a program that manipulates a file system. Files are simple objects and folders are composition of files and folders. However, for example, they both have size, name etc. functions. It would be easier and more convenient to treat both file and folder objects uniformly by defining a File System Resource Interface


The composite pattern applies when there is a part-whole hierarchy of objects and a client needs to deal with objects uniformly regardless of the fact that an object might be a leaf (simple object) or a branch (composite object).