Professional Documents
Culture Documents
Introduction To Patterns and Frameworks: Douglas C. Schmidt
Introduction To Patterns and Frameworks: Douglas C. Schmidt
Schmidt
Vanderbilt University 1
In a moment, we’ll explore how patterns are used to learn chess – e.g., relative value of certain pieces, strategic value of center
squares, power of a threat, etc.
Learning to develop good software is similar to learning to play good
However, to become a master of chess, one must study the
chess
games of other masters
– Though the consequences of failure are often far less dramatic!
– These games contain patterns that must be understood,
memorized, and applied repeatedly
There are hundreds of these patterns
First learn the rules Design patterns represent solutions to problems that arise when
– e.g., the algorithms, data structures and languages of software developing software within a particular context
– e.g., structured programming, modular programming, object Patterns capture the static and dynamic structure and collaboration
oriented programming, generic programming, etc. among key participants in software designs
However, to become a master of software design, one must – They are particularly useful for articulating how and why to
study the designs of other masters resolve non-functional forces
– These designs contain patterns that must be understood, Patterns facilitate reuse of successful software architectures and
memorized, and applied repeatedly designs
update()
get_state()
INHERITS CONTAINMENT
EVENT
SYSTEM template methods and the application
DATABASE CODE
LOOP
provides the variant hook methods
(B) FRAMEWORK ARCHITECTURE
Strategy
Handler Event Dispatcher
Protocol Patterns can be – Deal with decoupling interface and implementation of classes and
Filter
characterized as more objects
Adapter
abstract descriptions of
Active Object
frameworks, which are Behavioral patterns
Concurrency
Protocol Pipeline
Framework
Strategy
Framework implemented in a particular – Deal with dynamic interactions among societies of classes and
Streams Service Configurator
language objects
Mediator Strategy
– Mediator coordinates interactions between its associates – Abstraction for selecting one of many algorithms
Memento Template Method
– Snapshot captures and restores object states privately – Algorithm with some steps supplied by a derived class
Observer Visitor
– Dependents update automatically when a subject changes – Operations applied to elements of an heterogeneous object
structure
State
– Object whose behavior depends on its state
2. Solutions that require several steps – i.e., it must be useful! – It must provide sufficient
understanding to tailor the
Not all problems need all steps Have a context,
solution
Patterns can be overkill if solution is simple linear set of – It must describe where the
instructions Have a name
solution can be used
3. Solutions where the solver is more interested in the existence of the – It must be referred to
Recur,
solution than its complete derivation consistently
– It must be relevant in other
Patterns leave out too much to be useful to someone who really situations
wants to understand
– They can be a temporary bridge, however
Do
SUPERVISOR
HANDLERS
SUPER-
OO Patterns Douglas C. Schmidt
VISOR
www.cs.wustl.edu/schmidt/PDF/DSEJ-94.pdf
Case Study: A Reusable Object-Oriented
CALL CENTER
www.cs.wustl.edu/schmidt/PDF/ECOOP-
MANAGER
Communication Software Framework
: Reactor
Developing portable, reusable, and efficient communication software
SUPER-
System Overview
VISOR
is hard
HANDLERS
SWITCH
OS platforms are often fundamentally incompatible
NETWORK
– e.g., different concurrency and I/O models
Thus, it may be impractical to directly reuse: SUPER-
VISOR
SERVER
EVENT
– Algorithms
– Detailed designs
– Interfaces
Vanderbilt University
– Implementations
SUPER-
ERICSSON
VISOR
TELECOM
95.pdf
SWITCHES
OO Patterns
ERICSSON
MD110
MD110
Vanderbilt University 26
OO Patterns Douglas C. Schmidt OO Patterns Douglas C. Schmidt
INITIALIZATION
remove_handler(h) handlers
synchronous event INITIALIZE
1 N Event Handler register_handler(callback) Also note how
MODE
uses Handle owns handle_event(type) demuxing & dispatching REGISTER HANDLER
get_handle() long-running
get_handle() from event handling EXTRACT HANDLE
notifies handle_events() event handler
START EVENT LOOP
Forces Resolved select()
callbacks can
Synchronous Event Concrete FOREACH EVENT DO
Demultiplexer degrade quality
Event Efficiently demux handle_input()
EVENT HANDLING
handle_signal()
SIGNAL ARRIVES
(&eh, ACE_Event_Handler::READ_MASK);
OO Patterns Douglas C. Schmidt
reactor.handle_events ();
class My_Event_Handler : public ACE_Event_Handler {
public:
reactor.register_handler
reactor.register_handler
virtual int handle_input (ACE_HANDLE h) {
cout << "input on handle " << h << endl;
My_Event_Handler eh;
ACE_Reactor reactor;
return 0; }
virtual int handle_signal (int signum,
/* NOTREACHED */
(SIGINT, &eh);
siginfo_t *,
ucontext_t *) {
cout << "signal " << signum << endl;
return 0;
return 0; }
Vanderbilt University
for (;;)
virtual ACE_HANDLE get_handle (void) const {
return ACE_STDIN; }
OO Patterns
};
}
Vanderbilt University 32
Differences Between UNIX and Windows NT Lessons Learned from Case Study
Reactive vs. Proactive I/O
– Reactive I/O is synchronous Real-world constraints of OS platforms can preclude direct reuse of
– Proactive I/O is asynchronous communication software
Requires additional interfaces to “arm” the I/O mechanism – e.g., must often use non-portable features for performance
– See Proactor pattern
www.cs.wustl.edu/schmidt/POSA/ Reuse of design patterns may be the only viable means to leverage
previous development expertise
Other differences include
Design patterns are useful, but are no panacea
– Resource limitations
e.g., Windows WaitForMultipleObjects() limits – Managing expectations is crucial
HANDLEs per-thread to 64 – Deep knowledge of platforms, systems, and protocols is also very
– Demultiplexing fairness important
e.g., WaitForMultipleObjects always returns the lowest
active HANDLE
Successful patterns and frameworks can be boiled down to a few Often, aspects of a design “seem” constant until they are examined
key principles: in the light of the dependency structure of an application
1. Separate interface from implementation – At this point, it becomes necessary to refactor the framework or
2. Determine what is common and what is variable with an interface pattern to account for the variation
and an implementation
Frameworks often represent the distinction between commonality
– Common == stable
and variability via template methods and hook methods, respectively
3. Allow substitution of variable implementations via a common
interface
Dividing commonality from variability should be goal-oriented rather
than exhaustive
Design patterns enable large-scale reuse of software Patterns do not lead to direct code reuse
architectures
Patterns are deceptively simple
– They also help document systems to enhance understanding
Teams may suffer from pattern overload
Patterns explicitly capture expert knowledge and design
Patterns are validated by experience and discussion rather
tradeoffs, and make this expertise more widely available
than by automated testing
Patterns help improve developer communication
Integrating patterns into a software development process is a
– Pattern names form a vocabulary human-intensive activity
Patterns help ease the transition to object-oriented technology
Summary
Mature engineering disciplines have handbooks that describe
successful solutions to known problems
– e.g., automobile designers don’t design cars using the laws of
physics, they adapt adequate solutions from the handbook known
to work well enough
– The extra few percent of performance available by starting from
scratch typically isn’t worth the cost
Patterns can form the basis for the handbook of software
engineering
– If software is to become an engineering discipline, successful
practices must be systematically documented and widely
disseminated
Vanderbilt University 48