3. RA
D
Composite Design Pattern
Partitioning design pattern
(A group of objects is to be treated in the same way as a single
instance)(different objects – similar fashion)
Composite objects.
Objects that contain other objects
Drawing composed of graphic primitives
Lines, circles, rectangles, etc.
Menus.
Directories.
4. when we manipulate primitive objects
Lines must be
drawn,
moved,
resize
But we also need to perform the same on composites. Such
as drawings that are composed of those primitives
RA
D
5. RA
DTotal org salary
+ salary to the all departments
Total dept. salary
+ salary to al projects
Total project salary
+ project members
Recursive makes composite more beautiful
the salary of anything is the salary of self + the salary of all its sub groups.
7. Benefits
• Makes the clients simple. Clients can treat composite
structures and individual objects uniformly.
• Makes it easier to add new kind of components
• Can make your design general.
RA
D
Drawback
• Once tree structure is defined, the composite design
makes the tree overly general.
• Leaf class have to create some methods which has to
empty.