Design patterns Composite pattern

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Introduction

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

Remarks

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).



Got any Design patterns Question?