Software Design

Composite Pattern: Tree Structures Simplified

UML Class Diagrams · made in Skemio

UML class diagram illustrating the Composite Pattern with FileSystemItem interface implemented by File and Directory, where Directory aggregates FileSystemItem.
UML class diagram illustrating the Composite Pattern with FileSystemItem interface implemented by File and Directory, where Directory aggregates FileSystemItem.

What it shows

  • Unifies leaf nodes and containers under a single polymorphic interface.
  • Allows recursive operations like getSize() without explicit type checks.
  • Simplifies client code by eliminating nested instanceof branches.

The takeaway

Treat individual items and branch nodes identically through a shared interface to streamline tree logic.

More uml class diagrams