Monday, 18 April 2016

Composite pattern - Structural


  • treats a group of objects in similar way as a single object
  • creates a class that contains group of its own objects 
  • uses tree structures to represent part-whole hierarchies
    Build a complex object out of elemental objects and itself like a tree structure

Where to use ?
  • To represent a part-whole relationship like tree folder system
  • When clients ignore the difference between compositions of objects and individual objects
  • Used to let clients treat individual objects and compositions of objects uniformly.

Implementation example
  • Class Employee containing list of staff (List of Employee objects)
    Employee class can have methods to add its staff

No comments:

Post a Comment

Note: only a member of this blog may post a comment.