I would say the following is a decent example of the Command pattern:
class FileOpen extends ActionListener {
public void actionPerformed(ActionEvent evt) {
// code for the File->Open menu here
}
} // end FileOpen()
JMenuItem menuItem = new JMenuItem("Open");
menuItem.addActionListener(new FileOpen());
Command's idea is to encapsulate the request as an object, i.e. the request: ActionListener, and the object: new FileOpen(). Tommorow I could pass a different object that implements the ActionListener interface, and the JMenuItem could care less. I think java.lang.Runnable is probably the most intuitive example of the Command design pattern.
The whole point about Command is that different objects that implement the same interface can serve as the request object, without affecting the requestor.
I do agree with most of the other patterns you've catalogued, viz.
- Strategy - java.awt.LayoutManager, java.awt.image.ColorModel (very good examples)
- Observer/Observable - the 1.1 DelegationEvent model, ImageObserver, though
RMI's Remote interface is probably an equally good example
- Singleton - A good example is the java.awt.Toolkit (Toolkit.getDefaultToolkit() ensuring a single instance) or the Math class (private cons, one of the "requirements" for a Singleton).
- Abstract Factory - Toolkit (Sure. Also the SocketImplFactory, URLStreamHandlerFactory ... many others ... best example's probably the multiple look-and-feel classes in Swing)
- Command - adding Listener objects to an Observable, as I pointed out above
- Decorator - the whole java.io.Reader/Writer set of classes, that add functionality without subclassing, but end up creating a number of small objects in the process ... in fact, this is a "classic" example and it fits GOF's definition of Decorator to a T
- Proxy - the RMI stubs and skeletons model.
- Flyweight - Isn't that how javax.swing.text.Elements are stored in javax.swing.text.Document?