What major patterns do the Java APIs utilize?
Created May 4, 2012
John Moore Design patterns are used and supported
extensively throughout the Java APIs. Here are
some examples:
- The Model-View-Controller design pattern is used extensively throughout the Swing API.
- The getInstance() method in java.util.Calendar is an example of a simple form of the Factory Method design pattern.
- The classes java.lang.System and java.sql.DriverManager are examples of the Singleton pattern, although they are not implemented using the approach recommended in the GoF book but with static methods.
- The Prototype pattern is supported in Java through the clone() method defined in class Object and the use of java.lang.Cloneable interface to grant permission for cloning.
- The Java Swing classes support the Command pattern by providing an Action interface and an AbstractAction class.
- The Java 1.1 event model is based on the observer pattern. In addition, the interface java.util.Observable and the class java.util.Observer provide support for this pattern.
- The Adapter pattern is used extensively by the adapter classes in java.awt.event.
- The Proxy pattern is used extensively in the implementation of Java's Remote Method Invocation (RMI) and Interface Definition Language (IDL) features.
- The structure of Component and Container classes in java.awt provide a good example of the Composite pattern.
- The Bridge pattern can be found in the separation of the components in java.awt (e.g., Button and List), and their counterparts in java.awt.peer.
- [Felleisen 1998] Matthias Felleisen and Daniel P. Friedman, A Little Java, a Few Patterns, MIT Press, 1998.
- [Grand 1998] Mark Grand, Patterns in Java, Volume 1, John Wiley & Sons, 1998.
- [Grand 1999] Mark Grand, Patterns in Java, Volume 2, John Wiley & Sons, 1999.
- [Cooper 2000] James W. Cooper, Java Design Patterns: A Tutorial, Addison-Wesley, 2000.