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
Копасов Игорь (1), Т Е Л Е Ф О Н О Г Р А М М А ЗООМ, 20201546 п.80 использ., Oliy matematika, презентация индустрия мутакил иши, 3000 most common words in English, Sun'iy intellekt, 1638511850 AE, 1638511850 AE, Hisob-raqan (Patent boji), O'RQ-600 23-MODDA, Talabaning haftalik hisoboti namunasi , iikinchi hafta amaliyoti., Таҳлил тест
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 2022
ma'muriyatiga murojaat qiling

    Bosh sahifa
davlat universiteti
ta’lim vazirligi
axborot texnologiyalari
maxsus ta’lim
zbekiston respublikasi
guruh talabasi
O’zbekiston respublikasi
nomidagi toshkent
o’rta maxsus
davlat pedagogika
texnologiyalari universiteti
toshkent axborot
xorazmiy nomidagi
rivojlantirish vazirligi
pedagogika instituti
Ўзбекистон республикаси
tashkil etish
haqida tushuncha
таълим вазирлиги
vazirligi muhammad
O'zbekiston respublikasi
toshkent davlat
махсус таълим
respublikasi axborot
kommunikatsiyalarini rivojlantirish
vazirligi toshkent
saqlash vazirligi
fanidan tayyorlagan
bilan ishlash
Toshkent davlat
sog'liqni saqlash
uzbekistan coronavirus
respublikasi sog'liqni
coronavirus covid
koronavirus covid
vazirligi koronavirus
risida sertifikat
covid vaccination
qarshi emlanganlik
sertifikat ministry
vaccination certificate
Ishdan maqsad
fanidan mustaqil
matematika fakulteti
o’rta ta’lim
haqida umumiy
fanlar fakulteti
pedagogika universiteti
ishlab chiqarish
moliya instituti
fanining predmeti