Effective Java



Download 2,19 Mb.
Pdf ko'rish
bet257/341
Sana11.07.2022
Hajmi2,19 Mb.
#776765
1   ...   253   254   255   256   257   258   259   260   ...   341
Bog'liq
Effective Java



ITEM 67: OPTIMIZE JUDICIOUSLY
287
Consider the performance consequences of your API design decisions.
Making a public type mutable may require a lot of needless defensive copying
(Item 50). Similarly, using inheritance in a public class where composition would
have been appropriate ties the class forever to its superclass, which can place
artificial limits on the performance of the subclass (Item 18). As a final example,
using an implementation type rather than an interface in an API ties you to a
specific implementation, even though faster implementations may be written in
the future (Item 64). 
The effects of API design on performance are very real. Consider the 
getSize
method in the 
java.awt.Component
class. The decision that this performance-
critical method was to return a 
Dimension
instance, coupled with the decision that
Dimension
instances are mutable, forces any implementation of this method to
allocate a new 
Dimension
instance on every invocation. Even though allocating
small objects is inexpensive on a modern VM, allocating millions of objects
needlessly can do real harm to performance. 
Several API design alternatives existed. Ideally, 
Dimension
should have been
immutable (Item 17); alternatively, 
getSize
could have been replaced by two
methods returning the individual primitive components of a 
Dimension
object. In
fact, two such methods were added to 
Component
in Java 2 for performance
reasons. Preexisting client code, however, still uses the 
getSize
method and still
suffers the performance consequences of the original API design decisions.
Luckily, it is generally the case that good API design is consistent with good
performance. 

Download 2,19 Mb.

Do'stlaringiz bilan baham:
1   ...   253   254   255   256   257   258   259   260   ...   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