Design Patterns : Elements of Reusable Object-Oriented Software


Design Patterns: Elements of Reusable Object-Oriented Software



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

Design Patterns: Elements of Reusable Object-Oriented Software 
342 
converts conditional code (and virtual functions, in thecase of the State 
pattern) into a table look-up. 
The main advantage of tables is their regularity: You can change 
thetransition criteria by modifying data instead of changing programcode. 
There are some disadvantages, however: 
o
A table look-up is often less efficient than a (virtual)function 
call. 
o
Putting transition logic into a uniform, tabular format makes 
thetransition criteria less explicit and therefore harder to 
understand. 
o
It's usually difficult to add actions to accompany the 
statetransitions. The table-driven approach captures the states and 
theirtransitions, but it must be augmented to perform arbitrary 
computationon each transition. 
The key difference between table-driven state machines and the Statepattern 
can be summed up like this: The State pattern modelsstate-specific behavior, 
whereas the table-driven approach focuses ondefining state transitions. 
3.
Creating and destroying State objects.
A common implementation trade-off 
worth considering is whether(1) to create State objects only when they are 
needed and destroy themthereafter versus (2) creating them ahead of time 
and neverdestroying them. 
The first choice is preferable when the states that will be enteredaren't 
known at run-time, 
and
contexts change stateinfrequently. This approach 
avoids creating objects that won't beused, which is important if the State 
objects store a lot ofinformation. The second approach is better when state 
changes occurrapidly, in which case you want to avoid destroying states, 
becausethey may be needed again shortly. Instantiation costs are paid 
onceup-front, and there are no destruction costs at all. This approachmight 
be inconvenient, though, because the Context must keepreferences to all 
states that might be entered. 
4.
Using dynamic inheritance.
Changing the behavior for a particular request 
could be accomplishedby changing the object's class at run-time, but this 
is not possiblein most object-oriented programming languages. Exceptions 
includeSelf [US87] and other delegation-based languages thatprovide such 
a mechanism and hence support the State pattern directly.Objects in Self 
can delegate operations to other objects to achieve aform of dynamic 
inheritance. Changing the delegation target atrun-time effectively changes 
the inheritance structure. Thismechanism lets objects change their 
behavior and amounts to changingtheir class. 



Download 4,06 Mb.

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