Effective Java



Download 2,19 Mb.
Pdf ko'rish
bet324/341
Sana11.07.2022
Hajmi2,19 Mb.
#776765
1   ...   320   321   322   323   324   325   326   327   ...   341
Bog'liq
Effective Java



ITEM 90: CONSIDER SERIALIZATION PROXIES INSTEAD OF SERIALIZED INSTANCES
363
Item 90: Consider serialization proxies instead of serialized 
instances
As mentioned in Items 85 and 86 and discussed throughout this chapter, the deci-
sion to implement 
Serializable
increases the likelihood of bugs and security
problems as it allows instances to be created using an extralinguistic mechanism
in place of ordinary constructors. There is, however, a technique that greatly
reduces these risks. This technique is known as the 
serialization proxy pattern
.
The serialization proxy pattern is reasonably straightforward. First, design a
private static nested class that concisely represents the logical state of an instance
of the enclosing class. This nested class is known as the 
serialization proxy
of the
enclosing class. It should have a single constructor, whose parameter type is the
enclosing class. This constructor merely copies the data from its argument: it need
not do any consistency checking or defensive copying. By design, the default
serialized form of the serialization proxy is the perfect serialized form of the
enclosing class. Both the enclosing class and its serialization proxy must be
declared to implement 
Serializable
.
For example, consider the immutable 
Period
class written in Item 50 and
made serializable in Item 88. Here is a serialization proxy for this class. 
Period
is
so simple that its serialization proxy has exactly the same fields as the class:

Download 2,19 Mb.

Do'stlaringiz bilan baham:
1   ...   320   321   322   323   324   325   326   327   ...   341




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