Design Patterns : Elements of Reusable Object-Oriented Software


Design Patterns: Elements of Reusable Object-Oriented Software



Download 4,06 Mb.
Pdf ko'rish
bet106/288
Sana07.04.2022
Hajmi4,06 Mb.
#535140
1   ...   102   103   104   105   106   107   108   109   ...   288
Bog'liq
GOF Design Patterns

Design Patterns: Elements of Reusable Object-Oriented Software 
144 
Singleton 
Intent 
Ensure a class only has one instance, and provide a global point of access to 
it. 
Motivation 
It's important for some classes to have exactly one instance. Although there can 
be many printers in a system, there should be only one printer spooler. There 
should be only one file system and one window manager. A digital filter will have 
one A/D converter. An accounting system will be dedicated to serving one company. 
How do we ensure that a class has only one instance and that the instance is easily 
accessible? A global variable makes an object accessible, but it doesn't keep 
you from instantiating multiple objects. 
A better solution is to make the class itself responsible for keeping track of 
its sole instance. The class can ensure that no other instance can be created 
(by intercepting requests to create new objects), and it can provide a way to 
access the instance. This is the Singleton pattern. 
Applicability 
Use the Singleton pattern when 

there must be exactly one instance of a class, and it must be accessible 
to clients from a well-known access point. 

when the sole instance should be extensible by subclassing, and clients 
should be able to use an extended instance without modifying their code. 


Design Patterns: Elements of Reusable Object-Oriented Software 
145 
Structure 
Participants 

Singleton
o
defines an Instance operation that lets clients access its unique 
instance. Instance is a class operation (that is, a class method 
in Smalltalk and a static member function in C++). 
o
may be responsible for creating its own unique instance. 

Download 4,06 Mb.

Do'stlaringiz bilan baham:
1   ...   102   103   104   105   106   107   108   109   ...   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