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


Place as much of the logic of the program as possible into functions, operations that



Download 7,21 Mb.
Pdf ko'rish
bet171/343
Sana17.11.2022
Hajmi7,21 Mb.
#867526
1   ...   167   168   169   170   171   172   173   174   ...   343
Bog'liq
Eric Evans 2003 - Domain-Driven Design - Tackling Complexity in the Heart of Software

Place as much of the logic of the program as possible into functions, operations that
return results with no observable side effects. Strictly segregate commands (methods
that result in modifications to observable state) into very simple operations that do not
return domain information. Further control side effects by moving complex logic into
VALUE OBJECTS
 when a concept fitting the responsibility presents itself.
S
IDE-EFFECT-FREE FUNCTIONS
, especially in immutable 
VALUE OBJECTS
, allow safe combination of
operations. When a 
FUNCTION
is presented through an 
INTENTION-REVEALING INTERFACE
, a developer
can use it without understanding the detail of its implementation.
Example
Refactoring the Paint-Mixing Application Again
A program for paint stores can show a customer the result of mixing standard paints. Picking up
where we left off in the last example, here is the single domain class.
Figure 10.4.
public void mixIn(Paint other) {
volume = volume.plus(other.getVolume());
// Many lines of complicated color-mixing logic
// ending with the assignment of new red, blue,
// and yellow values.
}
Figure 10.5. The side effects of the 
mixIn()
 method


A lot is happening in the 
mixIn()
method, but this design does follow the rule of separating
modification from querying. One concern, which we'll take up later, is that the volume of the paint
2 object, the argument of the 
mixIn()
method, has been left in limbo. Paint 2's volume is
unchanged by the operation, which doesn't seem quite logical in the context of this conceptual
model. This was not a problem for the original developers because, as near as we can tell, they
had no interest in the paint 2 object after the operation, but it is hard to anticipate the
consequences of side effects or their absence. We'll return to this question soon in the discussion
of 
ASSERTIONS
. For now, let's look at color.
Color is an important concept in this domain. Let's try the experiment of making it an explicit
object. What should it be called? "Color" comes to mind first, but earlier knowledge crunching had
already yielded the important insight that color mixing is different for paint than it is for the more
familiar RGB light display. The name needs to reflect this.

Download 7,21 Mb.

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