Domain-Driven Design: Tackling Complexity in the Heart of Software


Figure 1.9. public int makeBooking(Cargo cargo, Voyage voyage) { double maxBooking = voyage.capacity() * 1.1



Download 7,21 Mb.
Pdf ko'rish
bet22/343
Sana17.11.2022
Hajmi7,21 Mb.
#867526
1   ...   18   19   20   21   22   23   24   25   ...   343
Bog'liq
Eric Evans 2003 - Domain-Driven Design - Tackling Complexity in the Heart of Software

Figure 1.9.
public int makeBooking(Cargo cargo, Voyage voyage) {
double maxBooking = voyage.capacity() * 1.1;
if ((voyage.bookedCargoSize() + cargo.size()) > maxBooking)
return –1;
int confirmation = orderConfirmationSequence.next();
voyage.addCargo(cargo, confirmation);
return confirmation;
}
Now an important business rule is hidden as a guard clause in an application method. Later, in
Chapter 4, we'll look at the principle of 
LAYERED ARCHITECTURE
, which would guide us to move the
over-booking rule into a domain object, but for now let's concentrate on how we could make this
knowledge more explicit and accessible to everyone on the project. This will bring us to a similar
solution.
As written, it is unlikely that any business expert could read this code to verify the rule, even
with the guidance of a developer.
1.
It would be difficult for a technical, non-businessperson to connect the requirement text with
the code.
2.
If the rule were more complex, that much more would be at stake.
We can change the design to better capture this knowledge. The overbooking rule is a policy.
Policy
is another name for the design pattern known as 
STRATEGY
(Gamma et al. 1995). It is
usually motivated by the need to substitute different rules, which is not needed here, as far as we
know. But the concept we are trying to capture does fit the 
meaning
of a policy, which is an
equally important motivation in domain-driven design. (See Chapter 12, "Relating Design Patterns
to the Model.")
Figure 1.10.


The code is now:
public int makeBooking(Cargo cargo, Voyage voyage) {
if (!overbookingPolicy.isAllowed(cargo, voyage)) return –1;
int confirmation = orderConfirmationSequence.next();
voyage.addCargo(cargo, confirmation);
return confirmation;
}
The new 

Download 7,21 Mb.

Do'stlaringiz bilan baham:
1   ...   18   19   20   21   22   23   24   25   ...   343




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