This repository demonstrates the Composite design pattern using a simple file system–style example written in Java.
The example shows how individual objects (files) and composite objects (folders containing files or other folders) can be treated uniformly through a shared interface.
The Composite pattern allows you to model tree-structured hierarchies where both:
- leaf nodes (single objects), and
- composite nodes (collections of objects)
support the same operations.
In this example:
- A File is a leaf node
- A Folder is a composite node
- Both expose a
getSize()operation - Client code does not need to know whether it is dealing with a file or a folder