Effective Java


Item 15: Minimize the accessibility of classes and members



Download 2,19 Mb.
Pdf ko'rish
bet73/341
Sana11.07.2022
Hajmi2,19 Mb.
#776765
1   ...   69   70   71   72   73   74   75   76   ...   341
Bog'liq
Effective Java

Item 15: Minimize the accessibility of classes and members
The single most important factor that distinguishes a well-designed component
from a poorly designed one is the degree to which the component hides its internal
data and other implementation details from other components. A well-designed
component hides all its implementation details, cleanly separating its API from its
implementation. Components then communicate only through their APIs and are
oblivious to each others’ inner workings. This concept, known as 
information
hiding
or
 encapsulation
, is a fundamental tenet of software design [Parnas72].
Information hiding is important for many reasons, most of which stem from
the fact that it 
decouples
the components that comprise a system, allowing them to
be developed, tested, optimized, used, understood, and modified in isolation. This
speeds up system development because components can be developed in parallel.
It eases the burden of maintenance because components can be understood more
quickly and debugged or replaced with little fear of harming other components.
While information hiding does not, in and of itself, cause good performance, it
enables effective performance tuning: once a system is complete and profiling has
determined which components are causing performance problems (Item 67), those
components can be optimized without affecting the correctness of others. Informa-
tion hiding increases software reuse because components that aren’t tightly cou-
pled often prove useful in other contexts besides the ones for which they were


CHAPTER 4
CLASSES AND INTERFACES
74
developed. Finally, information hiding decreases the risk in building large systems
because individual components may prove successful even if the system does not.
Java has many facilities to aid in information hiding. The 
access control
mecha-
nism [JLS, 6.6] specifies the 
accessibility
of classes, interfaces, and members. The
accessibility of an entity is determined by the location of its declaration and by
which, if any, of the access modifiers (
private

protected
, and 
public
) is present
on the declaration. Proper use of these modifiers is essential to information hiding.
The rule of thumb is simple: 

Download 2,19 Mb.

Do'stlaringiz bilan baham:
1   ...   69   70   71   72   73   74   75   76   ...   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