Design Patterns Composite Pattern - Design Patterns

What is Design Patterns Composite Pattern?

Composite pattern is used where we need to pleasure a group of objects in similar way as a single object. Composite pattern compose objects in term of a tree structure to stand for part as well as whole hierarchy. This type of design pattern comes under structural pattern as this pattern creates a tree structure of group of objects.

This pattern creates a class that contains group of its own objects. This class provides ways to change its group of same substance.
We are demonstrating use of composite pattern via following instance in which we will explain employee’s hierarchy of an organization.


We have a class Employee which acts as combination pattern performer class. CompositePatternDemo, our demo class will apply Employee class to add department level hierarchy and print all employees.


Step 1

Create Employee class having list of Employee objects.

Step 2

Apply the Employee class to make and print employee hierarchy.

Step 3

Verify the output.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

Design Patterns Topics