Design Patterns : Elements of Reusable Object-Oriented Software


Design Patterns: Elements of Reusable Object-Oriented Software



Download 4,06 Mb.
Pdf ko'rish
bet231/288
Sana07.04.2022
Hajmi4,06 Mb.
#535140
1   ...   227   228   229   230   231   232   233   234   ...   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 
343 
Sample Code 
The following example gives the C++ code for the TCP connectionexample described 
in the Motivation section. This example is asimplified version of the TCP protocol; 
it doesn't describe thecomplete protocol or all the states of TCPconnections.
8
First, we define the class TCPConnection, which provides aninterface for 
transmitting data and handles requests to change state. 
class TCPOctetStream; 
class TCPState
class TCPConnection { 
public: 
TCPConnection(); 
void ActiveOpen(); 
void PassiveOpen(); 
void Close(); 
void Send(); 
void Acknowledge(); 
void Synchronize(); 
void ProcessOctet(TCPOctetStream*); 
private: 
friend class TCPState; 
void ChangeState(TCPState*); 
private: 
TCPState* _state; 
}; 
TCPConnection keeps an instance of the TCPStateclass in the _state member variable. 
The classTCPState duplicates the state-changing interface ofTCPConnection. Each 
TCPState operation takes aTCPConnection instance as a parameter, lettingTCPState 
access data from TCPConnection andchange the connection's state. 
class TCPState { 
public: 
virtual void Transmit(TCPConnection*, TCPOctetStream*); 
virtual void ActiveOpen(TCPConnection*); 
virtual void PassiveOpen(TCPConnection*); 
virtual void Close(TCPConnection*); 
virtual void Synchronize(TCPConnection*); 


Design Patterns: Elements of Reusable Object-Oriented Software 
344 
virtual void Acknowledge(TCPConnection*); 
virtual void Send(TCPConnection*); 
protected: 
void ChangeState(TCPConnection*, TCPState*); 
}; 
TCPConnection delegates all state-specific requests to itsTCPState instance 
_state.TCPConnection also provides an operation for changing thisvariable to a 
new TCPState. The constructor forTCPConnection initializes the object to 
theTCPClosed state (defined later). 
TCPConnection::TCPConnection () { 
_state = TCPClosed::Instance(); 

void TCPConnection::ChangeState (TCPState* s) { 
_state = s; 

void TCPConnection::ActiveOpen () { 
_state->ActiveOpen(this); 

void TCPConnection::PassiveOpen () { 
_state->PassiveOpen(this); 

void TCPConnection::Close () { 
_state->Close(this);

void TCPConnection::Acknowledge () { 
_state->Acknowledge(this); 

void TCPConnection::Synchronize () { 
_state->Synchronize(this); 

TCPState implements default behavior for all requestsdelegated to it. It can also 
change the state of aTCPConnection with the ChangeState operation.TCPState is 
declared a friend of TCPConnection togive it privileged access to this operation. 
void TCPState::Transmit (TCPConnection*, TCPOctetStream*) { } 



Download 4,06 Mb.

Do'stlaringiz bilan baham:
1   ...   227   228   229   230   231   232   233   234   ...   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
qarshi emlanganlik
covid vaccination
risida sertifikat
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