Structural patterns focus on relationship in between objects. Group of entities that forms a structure (roughly a data structure). Ex: composite pattern to obtain a collection of object that are manipulated uniformly, see java TreeNode
. java.awt.Container
is a typical implementation of composite pattern: a GUI is obtained by aggregating GUI objects (A frame that contains a panel that contains a button and a label) :
Container panel = new JPanel();
Container subpanel = new JPanel();
Container button = new JButton("Click me");
// the following is independent of the real nature of objects, except that they are Containers
panel.add(subpanel);
subpanel.add(button);
Behavioral pattern focus on communication in between objects. Group of entities that communicates (roughly a network of communication). Ex: chain of responsability which lets you obtain a computation from a list of computation entities, see java Logger
. Java Iterator
or Observer
are very common behavioral patterns.
Collection<Integer> c = ...
// The following is independent of the real nature of the collection (List, Array, etc.)
Iterator<Integer> i = c.iterator();
while (i.hasNext()) {
Integer ii = i.next();
// do something with ii
}