Composition involves using recursion to abstract the super-class. It means everything can be treated as a Component and recursion over the structure is “elegantly” handled by polymorphism.

Benefits:

  • Can be used to represent a tree data structure.
  • Allows treating complex and simple objects in homogeneous manner.

Disadvantages:

  • Assumes there is a reasonably homogeneous interface for all elements of the graph, we don’t know where exactly to put operations for adding, removing and accessing children.
  • Recursive operations are distributed all over the class hierarchy. Can make understanding more difficult and can make extension more difficult.