Java Reference
In-Depth Information
programming (AOP), which allows you to “bolt on” extra functionality from the outside of
your classes. AOP is provided by the Java EE using EJB Interception, and by the Spring
Framework AOP mechanism.
Use Design Patterns
In the Preface , I mentioned Design Patterns (Addison-Wesley) as one of the Very Important
Books on object-oriented programming. Often called the “Gang of Four” (GoF) book for its
four authors, it provides a powerful catalog of things that programmers often reinvent. A
Design Pattern provides a statement of a problem and its solution(s), rather like the present
book, but generally at a higher level of abstraction. It is as important for giving a standard
vocabulary of design as it is for its clear explanations of how the basic patterns work and
how they can be implemented.
Table 8-1 shows some example uses of Design Patterns in the standard API.
Table 8-1. Design Patterns in the JavaSE API
Pattern
name
Meaning
Examples in Java API
Command
Encapsulate requests, allowing queues of re-
quests, undoable operations, etc.
javax.swing.Action;
javax.swing.undo.UndoableEdit
Decorator
One class “decorates” another
Swing Borders
Factory
Method
One class makes up instances for you, con-
trolled by subclasses
getInstance (in Calendar , Format , Locale …); sock-
et constructor; RMI InitialContext
Iterator
Loop over all elements in a collection, visit-
ing each exactly once
Iterator ; older Enumeration ; java.sql.ResultSet
Model-
View-Con-
troller
Model represents data; View is what the
user sees; Controller responds to user re-
quests
ActionListener and friends; Observer/Observable ;
used internally by all visible Swing components
Proxy
One object stands in for another
RMI, AOP, Dynamic Proxy
Singleton
Only one instance may exist
java.lang.Runtime, java.awt.Toolkit
Search WWH ::




Custom Search