Professional Documents
Culture Documents
Reusability Revisited
ceg860 (Prasa
L156DP
etc)
Thread,
etc)
L156DP
L156DP
ceg860 (Prasa
L156DP
ceg860 (Prasa
Server
Proxy
L156DP
Translator/Adapter
Intermediary acts like a translator between the client
and the server.
E.g., Format/protocol conversions.
Client
ceg860 (Prasa
Adapter
L156DP
Server
Facade
Intermediary acts like a focal point distributing
work to other agents.
E.g., telnet, ftp, web-browser.
E.g., local/network files, devices, ... UNIX files
Server1
Client
Facade
Server2
Server3
ceg860 (Prasa
L156DP
Bridge/Abstract Factory/Handle
Intermediary defines the interface but not the
implementation.
E.g., Motif/Mac/Windows look and feel.
E.g., java.io.InputStream, java.io.OutputStream.
Impl1
Client
Bridge
Impl2
Impl3
ceg860 (Prasa
L156DP
etc.)
L156DP
Model/View/Controller (Smalltalk)
Pattern for graphical interactive system
Model
: Application Object
View
: Screen Presentation
Controller : User interaction
L156DP
10
L156DP
11
ceg860 (Prasa
L156DP
12
In each state:
display panel seeking
user input / new request
read user input/query
checking for consistency
process user request
update database
transition to next state
ceg860 (Prasa
Example
Airline Reservation
States
User Identification
Enquiry on flights
L156DP
13
ceg860 (Prasa
L156DP
14
display
ceg860 (Prasa
transition
execute_state
read_input
L156DP
final
process
15
void execute_session() {
int state, next;
state = initial;
do {
execute_state(state,next);
state = transition(state,next);
} while (! is_final(state));
}
void execute_state(int state,int next) {
T input;
int next;
display(state);
read_input(state);
process(state,next);
}
ceg860 (Prasa
L156DP
16
L156DP
17
DateType
Data1
Proc1
Data3
Data2
Routine
Proc1
Proc2
Proc3
ceg860 (Prasa
Proc2
Data3
Proc3
L156DP
18
Object-Oriented Architecture
abstract class State {
int next;
T input;
abstract void display();
abstract void read_input();
abstract void process();
void execute(next) {
display();
read_input();
process();
}}
ceg860 (Prasa
L156DP
19
class Application {
State[][] transition; State[] associated_state;
Application(int n, int m) {
transition
= new State[n][m];
associated_state = new State[n];
}
void put_state(State s, int i){}
void put_transition(State src, State dst,
int choice){}
int initial;
void choose_initial(int i){}
void execute {
State s;
int stn = initial;
while ( !stn ) {
s = associated_state(stn);
s.execute();
stn = transition(stn,s.next)
}}}
ceg860 (Prasa
L156DP
20
Class Application
ceg860 (Prasa
L156DP
21
Undo-Redo Facility
(using history)
Inheritance, Dynamic Binding,
Polymorphism
ceg860 (Prasa
L156DP
22
Requirements
Applicable to wide class of interactive
applications.
Incremental w.r.t. command additions.
Use reasonable amount of storage.
Support arbitrary-level of undoing.
Practical Issues:
Part of the User Interface.
Some commands undoable.
ceg860 (Prasa
L156DP
23
L156DP
24
A History List
isItem()
item()
...
isFirst()
count
...
prev
cursor
next
isLast()
! isLast()
ceg860 (Prasa
L156DP
25
Read_decode_request;
if (request instanceOf Command) {
if (! History.isLast())
History.removeAllItemsToRight();
History.addItem(request);
request.execute();
} else if (requested instanceOf Undo)
if (History.isItem()) {
History.item.undo();
History.prev;
} else ;// nothing to undo
else if (requested instanceOf Redo)
if (! History.isLast()) {
History.next;
History.item.redo();
} else ; // nothing to redo
ceg860 (Prasa
L156DP
26
ceg860 (Prasa
L156DP
27