Structural Design Patterns
Observer: Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
Used in jdk as:
-
java.util.Observer/java.util.Observable
All implementations of java.util.EventListener (practically all over Swing thus)
javax.servlet.http.HttpSessionBindingListener
javax.servlet.http.HttpSessionAttributeListener
javax.faces.event.PhaseListener
Adapter – Convert the interface of a class into another interface clients expect. / Adapter lets classes work together, that could not otherwise because of incompatible interfaces. Note that there are two types of adapter, one is class level adapter and other is object level adapter. Examples –
java.io.InputStreamReader(InputStream) (returns a Reader)
java.io.OutputStreamWriter(OutputStream) (returns a Writer)
javax.xml.bind.annotation.adapters.XmlAdapter#marshal() and #unmarshal()
Bridge Pattern: Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.
Used in jdk:
JDBC-ODBC Bridge
Composite: Compose objects into tree structures to represent part-whole hierarchies. / Composite lets clients treat individual objects and compositions of objects uniformly.
Used in jdk:
java.util.Map#putAll
(Map)
java.util.List#addAll
(Collection)
java.util.Set#addAll
(Collection)
java.nio.ByteBuffer#put
(ByteBuffer) (also on CharBuffer, ShortBuffer, IntBuffer, LongBuffer, FloatBuffer and DoubleBuffer)
java.awt.Container#add
(Component) (practically all over Swing thus)
Includes in JSP ( to manage the views as an example of Composite view)