Clean Code



Download 3,58 Mb.
Pdf ko'rish
bet127/384
Sana05.04.2022
Hajmi3,58 Mb.
#530298
1   ...   123   124   125   126   127   128   129   130   ...   384
Bog'liq
Clean Code

Chapter 8: Boundaries
Clean Boundaries
Interesting things happen at boundaries. Change is one of those things. Good software
designs accommodate change without huge investments and rework. When we use code
that is out of our control, special care must be taken to protect our investment and make
sure future change is not too costly. 
Code at the boundaries needs clear separation and tests that define expectations. We
should avoid letting too much of our code know about the third-party particulars. It’s better
to depend on something 
you
control than on something you don’t control, lest it end up
controlling you. 
We manage third-party boundaries by having very few places in the code that refer to
them. We may wrap them as we did with 
Map
, or we may use an A
DAPTER
to convert from
our perfect interface to the provided interface. Either way our code speaks to us better,
promotes internally consistent usage across the boundary, and has fewer maintenance
points when the third-party code changes. 
Bibliography
[BeckTDD]:
Test Driven Development,
Kent Beck, Addison-Wesley, 2003.
[GOF]:
Design Patterns: Elements of Reusable Object Oriented Software,
Gamma et al.,
Addison-Wesley, 1996.
[WELC]:
Working Effectively with Legacy Code,
Addison-Wesley, 2004.


121
9
Unit Tests
Our profession has come a long way in the last ten years. In 1997 no one had heard of
Test Driven Development. For the vast majority of us, unit tests were short bits of throw-
away code that we wrote to make sure our programs “worked.” We would painstakingly
write our classes and methods, and then we would concoct some ad hoc code to test
them. Typically this would involve some kind of simple driver program that would allow
us to manually interact with the program we had written.
I remember writing a C++ program for an embedded real-time system back in the
mid-90s. The program was a simple timer with the following signature:
void Timer::ScheduleCommand(Command* theCommand, int milliseconds) 
The idea was simple; the 
execute
method of the 
Command
would be executed in a new
thread after the specified number of milliseconds. The problem was, how to test it.


122

Download 3,58 Mb.

Do'stlaringiz bilan baham:
1   ...   123   124   125   126   127   128   129   130   ...   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