Clean Code



Download 3,58 Mb.
Pdf ko'rish
bet171/384
Sana05.04.2022
Hajmi3,58 Mb.
#530298
1   ...   167   168   169   170   171   172   173   174   ...   384
Bog'liq
Clean Code

Chapter 12: Emergence
replaceImage(ImageUtilities.getScaledImage(
image, scalingFactor, scalingFactor));
}
public synchronized void rotate(int degrees) {
replaceImage(ImageUtilities.getRotatedImage(image, degrees));
}
private void replaceImage(RenderedOp newImage) {
image.dispose();
System.gc();
image = newImage;
}
As we extract commonality at this very tiny level, we start to recognize violations of SRP.
So we might move a newly extracted method to another class. That elevates its visibility.
Someone else on the team may recognize the opportunity to further abstract the new
method and reuse it in a different context. This “reuse in the small” can cause system com-
plexity to shrink dramatically. Understanding how to achieve reuse in the small is essential
to achieving reuse in the large.
The T
EMPLATE
M
ETHOD
2
pattern is a common technique for removing higher-level
duplication. For example: 
public class VacationPolicy {
public void accrueUSDivisionVacation() {
// code to calculate vacation based on hours worked to date
// ...
// code to ensure vacation meets US minimums
// ...
// code to apply vaction to payroll record
// ...
}
public void accrueEUDivisionVacation() {
// code to calculate vacation based on hours worked to date
// ...
// code to ensure vacation meets EU minimums
// ...
// code to apply vaction to payroll record
// ...
}
}
The code across 
accrueUSDivisionVacation
and
accrueEuropeanDivisionVacation
is largely
the same, with the exception of calculating legal minimums. That bit of the algorithm
changes based on the employee type.
We can eliminate the obvious duplication by applying the T
EMPLATE
M
ETHOD
pattern.
abstract public class VacationPolicy {
public void accrueVacation() {

Download 3,58 Mb.

Do'stlaringiz bilan baham:
1   ...   167   168   169   170   171   172   173   174   ...   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