Brain Dump

Composite Pattern

Tags
soft-eng

Is a software design pattern where a group of objects can be interacted with like a single instance of the object. This is done by having the instance store a collection of instances deriving from its parent class and then calling the same action on all of those objects when that action is called on it.

This pattern coordinates objects with similar interfaces [see page 24, indicating] loose coupling.

\begin{figure}
  \centering
  \begin{tikzpicture}
    \umlsimpleclass{Client}
    \umlclass[x=3cm]{Component}{}{action1() \\ action2()}
    \umlclass[x=7cm, y=1.5cm]{Leaf}{}{action1() \\ action2()}
    \umlclass[x=7cm, y=-2cm]{Composite}
      {}
      {add(Component) \\
       remove(Component) \\
       action1() \\
       action2()}

     \umlnote[x=1cm, y=-3cm]{Composite}{forall c in children: c.action1()}
     \umlVHinherit{Composite}{Component}
     \umlVHinherit{Leaf}{Component}
     \umluniassoc{Client}{Component}
     \umlHVaggreg{Composite}{Component};
  \end{tikzpicture}
  \caption{The composite pattern.}
\end{figure}