Clean Code



Download 3,58 Mb.
Pdf ko'rish
bet155/384
Sana05.04.2022
Hajmi3,58 Mb.
#530298
1   ...   151   152   153   154   155   156   157   158   ...   384
Bog'liq
Clean Code

Separation of Main
One way to separate construction from use is simply to move all aspects of construction to
main
, or modules called by 
main
, and to design the rest of the system assuming that all
objects have been constructed and wired up appropriately. (See Figure 11-1.)
The flow of control is easy to follow. The 
main
function builds the objects necessary
for the system, then passes them to the application, which simply uses them. Notice the
direction of the dependency arrows crossing the barrier between 
main
and the application.
They all go one direction, pointing away from main. This means that the application has no
knowledge of 
main
or of the construction process. It simply expects that everything has
been built properly.
Factories
Sometimes, of course, we need to make the application responsible for 
when
an object gets
created. For example, in an order processing system the application must create the
1.
[Mezzaros07].


156
Chapter 11: Systems
LineItem
instances to add to an 
Order
. In this case we can use the A
BSTRACT
F
ACTORY
2
pattern to give the application control of 
when
to build the 
LineItems
, but keep the details
of that construction separate from the application code. (See Figure 11-2.)
Again notice that all the dependencies point from 
main
toward the 
OrderProcessing
application. This means that the application is decoupled from the details of how to
build a 
LineItem
. That capability is held in the 
LineItemFactoryImplementation
, which
is on the 
main
side of the line. And yet the application is in complete control of when
the
LineItem
instances get built and can even provide application-specific constructor
arguments. 

Download 3,58 Mb.

Do'stlaringiz bilan baham:
1   ...   151   152   153   154   155   156   157   158   ...   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