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



Download 7,21 Mb.
Pdf ko'rish
bet175/343
Sana17.11.2022
Hajmi7,21 Mb.
#867526
1   ...   171   172   173   174   175   176   177   178   ...   343
Bog'liq
Eric Evans 2003 - Domain-Driven Design - Tackling Complexity in the Heart of Software

We Can See Clearly Now
As we search for a better model, we have significant advantages over the original designers,
because of the knowledge crunching and refactoring to deeper insight that has happened in the
interim. For example, we compute color using a 
SIDE-EFFECT-FREE FUNCTION
on a 
VALUE OBJECT
. This
means we can repeat the calculation any time we need to. We should take advantage of that.
We seem to be giving 
Paint
two different basic responsibilities. Let's try splitting them.
Now there is only one command, 
mixIn()
. It just adds an object to a collection, an effect apparent
from an intuitive understanding of the model. All other operations are 
SIDE-EFFECT-FREE FUNCTIONS
.
A test method confirming one of the 
ASSERTIONS
listed in Figure 10.10 could look something like
this (using the JUnit test framework):
public void testMixingVolume {
PigmentColor yellow = new PigmentColor(0, 50, 0);
PigmentColor blue = new PigmentColor(0, 0, 50);
StockPaint paint1 = new StockPaint(1.0, yellow);
StockPaint paint2 = new StockPaint(1.5, blue);
MixedPaint mix = new MixedPaint();
mix.mixIn(paint1);
mix.mixIn(paint2);
assertEquals(2.5, mix.getVolume(), 0.01);
}
Figure 10.10.


This model captures and communicates more of the domain. The invariants and post-conditions
make common sense, which will make them easier to maintain and use.
The communicativeness of the 
INTENTION-REVEALING INTERFACES
, combined with the predictability
given by 
SIDE-EFFECT-FREE FUNCTIONS
and 
ASSERTIONS
, should make encapsulation and abstraction
safe.
The next ingredient in recombinable elements is effective decomposition. . . .
[ Team LiB ]


[ Team LiB ]

Download 7,21 Mb.

Do'stlaringiz bilan baham:
1   ...   171   172   173   174   175   176   177   178   ...   343




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2025
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