Clean Code



Download 3,58 Mb.
Pdf ko'rish
bet142/384
Sana05.04.2022
Hajmi3,58 Mb.
#530298
1   ...   138   139   140   141   142   143   144   145   ...   384
Bog'liq
Clean Code

Listing 10-1 (continued)
Too Many Responsibilities


138
Chapter 10: Classes
But what if 
SuperDashboard
contained only the methods shown in Listing 10-2?
Five methods isn’t too much, is it? In this case it is because despite its small number
of methods, 
SuperDashboard
has too many 
responsibilities
.
The name of a class should describe what responsibilities it fulfills. In fact, naming
is probably the first way of helping determine class size. If we cannot derive a concise
name for a class, then it’s likely too large. The more ambiguous the class name, the more
likely it has too many responsibilities. For example, class names including weasel words
like 
Processor
or
Manager
or
Super
often hint at unfortunate aggregation of
responsibilities.
We should also be able to write a brief description of the class in about 25 words,
without using the words “if,” “and,” “or,” or “but.” How would we describe the
SuperDashboard
? “The 
SuperDashboard
provides access to the component that last held the
focus, and it also allows us to track the version and build numbers.” The first “and” is a
hint that 
SuperDashboard
has too many responsibilities.
The Single Responsibility Principle
The Single Responsibility Principle (SRP)
2
states that a class or module should have one,
and only one, 
reason to change
. This principle gives us both a definition of responsibility,
and a guidelines for class size. Classes should have one responsibility—one reason to
change.
public void setAçowDragging(boolean allowDragging) 
public boolean allowDragging() 
public boolean isCustomizing() 
public void setTitle(String title) 
public IdeMenuBar getIdeMenuBar() 
public void showHelper(MetaObject metaObject, String propertyName)
// ... many non-public methods follow ...
}

Download 3,58 Mb.

Do'stlaringiz bilan baham:
1   ...   138   139   140   141   142   143   144   145   ...   384




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