Linda, Since you are clearly familiar with so many patterns, what, in your opinion, are the 10 most frequently used patterns in Java? I suspect Singleton, Facade and Observer would make the list. But I'm guessing that there will probably be a few that I don't know on the list.
Originally posted by Paul Wheaton: Linda, Since you are clearly familiar with so many patterns, what, in your opinion, are the 10 most frequently used patterns in Java? I suspect Singleton, Facade and Observer would make the list. But I'm guessing that there will probably be a few that I don't know on the list.
Hi Paul, One of the parts of the Alamanac that I am most happy about is the list of experience papers that follow each pattern. These are published reports of actual use of the pattern. I'm not sure how many of these papers were written by Java users but using the number of papers as an indicator of over-all use it's easy to see that the patterns in the GoF book lead the others. I don't think this is because they are better than the others -- only more well known. Here's the list of GoF patterns in order of use with the most used listed first and equal numbers of uses on the same line: Adapter Composite, Strategy Observer, State Command, Mediator, Singleton Abstract Factory, Factory Method, Facade Template Method, Visitor Builder, Prototype, Bridge, Proxy Decorator, Memento Iterator Flyweight, Interpeter had no experience reports I think we need more experienced users to tell about their experience. We all learn more when he hear how someone used a pattern to solve a real problem *and* when a detailed example in a particular domain is given. Thanks for an interesting question!
Dont forget Strategy and Decorator! Decorator is heavily used in AWT and Swing. ScrollPane and JScrollPane are Decorators. The high-level Stream classes are also Decorators. The LayoutManagers are Strategies.
If you want an obscure one, I really like Transfer Vector which comes from the Shlaer-Mellor methodology way back when. This states to define your subsystems/components (they called these domains) in your system and derive a generic type that can be used for communication between the subsystems. The "wormhole" is the particular entry/exit point from the domain and the bridge is the transfer method. This was all conceived before GoF - it is interesting to examine.
1. TYPED MESSAGE may not be official yet but it's primary example is taken directly from the Java Event Handling model. 2. ITERATOR is directly supported by the Java2 API. (Look at Iterator Interface and ArrayLists) 3. DECORATOR is used in Swing. (Look at JScrollPane and any component that scrollable) 4. OBSERVER is used directly by the Java2 API. (Look at, Observer, Observable) 5. ADAPTER is an obvious one if you've use Anonymous inner classes, (see WindowAdapter) And much more, Im sure. Out of the orginal 23 GoF patterns, I'm guessing most of them or some variation is not only used in Java2 by developers but even directly implemented like the ones above. ------------------ David Roberts, SCJP2 [This message has been edited by David Roberts (edited March 14, 2001).] [This message has been edited by David Roberts (edited March 14, 2001).]