Given by Konrad Olszewski at Tango Group Internal Technology Seminars on Spring 99. Foils prepared May 19 99
Outside Index
Summary of Material
Rationale |
Swing architecture |
Observer |
Factory |
Template |
Command |
Summary |
Outside Index
Summary of Material
Konrad Olszewski |
Syracuse 1999 |
Rationale |
Swing architecture |
Observer |
Factory |
Template |
Command |
Summary |
"Once you understand the design patterns and have had an `Aha!' (and not just `Huh?') experience with them, you won't ever think about object-oriented design in the same way." |
Gamma et al |
A pattern describes a reoccurring problem and provides a customizable solution to that problem. |
Design patterns locate themselves between simple algorithms and data structure (e.g. linked lists) and application designs. |
Model - holds the information about component state |
Controller - receives and responds to input |
View - displays the component |
notifications |
Data to screen |
Application code |
notifications |
Mouse, focus, keyboard, etc. |
Main components (e.g. JList, JButton, etc.) are wrappers hiding the internal complexity |
View and controller are usually integrated into one class (usually with suffix UI, eg. BasicButtonUI) |
components that are containers may use custom renderers to display their data (e.g. DefaultListCellRenderer) |
Defines a one-to-many dependency between the objects so that when one object changes state, all its dependents are notified and updated automatiacally |
observers |
subject |
All the listeners are observers |
Can be initialized with either simple data (array, Vector) or a ListModel |
ListModel makes association between model and view and takes care of notifications |
Swing provides a following hierarchy:
|
TAgent |
TControlListener |
DefaultListModel |
UserListModel |
JList |
UserRenderer |
Provides an interface for creating objects without specifying their concrete classes |
Hides the complexity of objects |
Example: creation of different GUI elements in Swing (each element is represented by different class depending on the Look-and-Feel) |
Factory |
createProduct() |
Client |
ConcreteProduct1 |
ConcreteProduct2 |
AbstractProduct |
SessionFactory |
createSession(AT) |
SessionStore |
StandardSession |
BVSession |
Session |
Template lets its subclasses redefine some parts of behavior without changing the class structure. |
Very often used!!! |
AbstractClass |
template() |
operation1() |
operation2() |
operation1(); |
operation2(); |
AudioProvider |
run() |
getData() |
decodeData() |
pushData() |
HTTPProvider |
FileProvider |
FTPProvider |
getData(); |
decodeData(); |
pushData(); |
Command encapsulates a request as an object |
Command decouples the object that invokes the operation from the one that knows how to perform it |
Client |
Invoker |
TAgent |
TDataListener |
MessageReceiver |
Message |
execute() |
Design Patterns characteristics:
|
Design Patterns. Elements of Reusable Object-Oriented Software by E. Gamma, R. Helm, R. Johnson and J. Vlissides |
Core Java Foundation Classes by Kim Topley |