Java Design Patterns

by Jeff Hunter, Sr. Database Administrator

Common Java Design Patterns
Pattern Name Meaning Examples in Java API
Factory One class that makes up instances for you, controlled by subclasses getInstance(in Calendar, Format, Local...);
socket constructor;
RMI InitialContext
Iterator Loop over all elements in a collection (or container), visiting each element only once. Iterator;
(or Enumeration for pre Java 2)
Singleton Only one instance may exist for a given class. java.awt.Toolkit
Memento Capture and externalize an object's state for later reconstruction. Serializing an object
Command Encapsulate requests, allowing queues of requests, undoable operations, etc. java.awt.Command
Model-View-Controller Model represents data; View is what user user sees; Controller responds to user request. Observer/Observable;