Design Patterns : Elements of Reusable Object-Oriented Software



Download 4,06 Mb.
Pdf ko'rish
bet228/288
Sana07.04.2022
Hajmi4,06 Mb.
#535140
1   ...   224   225   226   227   228   229   230   231   ...   288
Bog'liq
GOF Design Patterns

Structure 
Participants 

Context
(TCPConnection) 
o
defines the interface of interest to clients.
o
maintains an instance of a ConcreteState subclass that defines 
thecurrent state. 


Design Patterns: Elements of Reusable Object-Oriented Software 
340 

State
(TCPState) 
o
defines an interface for encapsulating the behavior associated with 
aparticular state of the Context. 

ConcreteState subclasses
(TCPEstablished, TCPListen, TCPClosed) 
o
each subclass implements a behavior associated with a state ofthe 
Context. 
Collaborations 

Context delegates state-specific requests to the current 
ConcreteStateobject. 

A context may pass itself as an argument to the State objecthandling the 
request. This lets the State object accessthe context if necessary. 

Context is the primary interface for clients. Clients can configure acontext 
with State objects. Once a context is configured, its clients don't have 
to deal with the State objects directly.

Either Context or the ConcreteState subclasses can decide which 
statesucceeds another and under what circumstances. 
Consequences 
The State pattern has the following consequences: 
1.
It localizes state-specific behavior and partitionsbehavior for different 
states.
The State pattern puts all behavior associated with a particular 
stateinto one object. Because all state-specific code lives in a 
Statesubclass, new states and transitions can be added easily by definingnew 
subclasses. 
An alternative is to use data values to define internal states andhave 
Context operations check the data explicitly. But then we'dhave look-alike 
conditional or case statements scattered throughoutContext's 
implementation. Adding a new state could requirechanging several 
operations, which complicates maintenance. 
The State pattern avoids this problem but might introduce another,because 
the pattern distributes behavior for different states acrossseveral State 
subclasses. This increases the number of classes and isless compact than 
a single class. But such distribution is actuallygood if there are many 
states, which would otherwise necessitate largeconditional statements. 
Like long procedures, large conditional statements are undesirable.They're 
monolithic and tend to make the code less explicit, whichin turn makes them 



Download 4,06 Mb.

Do'stlaringiz bilan baham:
1   ...   224   225   226   227   228   229   230   231   ...   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