Design Patterns : Elements of Reusable Object-Oriented Software


Design Patterns: Elements of Reusable Object-Oriented Software



Download 4,06 Mb.
Pdf ko'rish
bet232/288
Sana07.04.2022
Hajmi4,06 Mb.
#535140
1   ...   228   229   230   231   232   233   234   235   ...   288
Bog'liq
GOF Design Patterns

Design Patterns: Elements of Reusable Object-Oriented Software 
345 
void TCPState::ActiveOpen (TCPConnection*) { } 
void TCPState::PassiveOpen (TCPConnection*) { } 
void TCPState::Close (TCPConnection*) { } 
void TCPState::Synchronize (TCPConnection*) { } 
void TCPState::ChangeState (TCPConnection* t, TCPState* s) { 
t->ChangeState(s); 

Subclasses of TCPState implement state-specific behavior. ATCP connection can 
be in many states: Established, Listening, Closed,etc., and there's a subclass 
of TCPState for each state.We'll discuss three subclasses in detail: 
TCPEstablished,TCPListen, and TCPClosed. 
class TCPEstablished : public TCPState { 
public: 
static TCPState* Instance(); 
virtual void Transmit(TCPConnection*, TCPOctetStream*); 
virtual void Close(TCPConnection*); 
}; 
class TCPListen : public TCPState { 
public: 
static TCPState* Instance(); 
virtual void Send(TCPConnection*); 
// ...
}; 
class TCPClosed : public TCPState { 
public: 
static TCPState* Instance(); 
virtual void ActiveOpen(TCPConnection*); 
virtual void PassiveOpen(TCPConnection*); 
// ...
}; 
TCPState subclasses maintain no local state, sothey can be shared, and only one 
instance of each is required. Theunique instance of each TCPState subclass is 
obtained by thestatic Instanceoperation.
9


Design Patterns: Elements of Reusable Object-Oriented Software 
346 
Each TCPState subclass implements state-specific behaviorfor valid requests in 
the state: 
void TCPClosed::ActiveOpen (TCPConnection* t) { 
// send SYN, receive SYN, ACK, etc. 
ChangeState(t, TCPEstablished::Instance()); 

void TCPClosed::PassiveOpen (TCPConnection* t) { 
ChangeState(t, TCPListen::Instance()); 

void TCPEstablished::Close (TCPConnection* t) { 
// send FIN, receive ACK of FIN 
ChangeState(t, TCPListen::Instance()); 

void TCPEstablished::Transmit ( TCPConnection* t, TCPOctetStream* o ) { 
t->ProcessOctet(o); 

void TCPListen::Send (TCPConnection* t) { 
// send SYN, receive SYN, ACK, etc. 
ChangeState(t, TCPEstablished::Instance()); 

After performing state-specific work, these operations call theChangeState 
operation to change the state ofthe TCPConnection. TCPConnection itself 
doesn'tknow a thing about the TCP connection protocol; it's theTCPState subclasses 
that define each state transitionand action in TCP. 
Known Uses 
Johnson and Zweig [JZ91] characterize theState pattern and its application to 
TCP connection protocols. 
Most popular interactive drawing programs provide "tools" forperforming 
operations by direct manipulation. For example, aline-drawing tool lets a user 
click and drag to create a new line. Aselection tool lets the user select shapes. 
There's usually a paletteof such tools to choose from. The user thinks of this 
activity aspicking up a tool and wielding it, but in reality the editor'sbehavior 
changes with the current tool: When a drawing tool is activewe create shapes; 



Download 4,06 Mb.

Do'stlaringiz bilan baham:
1   ...   228   229   230   231   232   233   234   235   ...   288




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish