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


Share Pie seems to be obscuring the relationship of the  Share Pie



Download 7,21 Mb.
Pdf ko'rish
bet196/343
Sana17.11.2022
Hajmi7,21 Mb.
#867526
1   ...   192   193   194   195   196   197   198   199   ...   343
Bog'liq
Eric Evans 2003 - Domain-Driven Design - Tackling Complexity in the Heart of Software

Share Pie
seems to be obscuring the
relationship of the 
Share Pie
and the 
Shares
. What would happen if we made 
Share Pie

VALUE
OBJECT
?
This would mean that 
increase(Map)
and 
decrease(Map)
would not be allowed, because the
Share Pie
would have to be immutable. To change the 
Share Pie
's value, the whole 
Pie
would
have to be replaced. So you could have operations such as 
addShares(Map)
that would return a
whole new, larger 
Share Pie
.
Let's go all the way to 
CLOSURE OF OPERATIONS
. Instead of "increasing" a 
Share Pie
or adding
Shares
to it, just add two 
Share Pies 
together: the result is the new, larger 
Share Pie
.


We can partially close the 
prorate()
operation over 
Share Pie 
just by changing the return type.
Renaming it to 
prorated()
emphasizes its lack of side effects. "Shares Math" starts to take shape,
initially with four operations.
Figure 10.20.
We can make some well-defined 
ASSERTIONS
about our new 
VALUE OBJECTS
, the 
Share Pies
. Each
method means something.
[View full width]
public class SharePie {
private Map shares = new HashMap();
//Accessors and other straightforward methods are omitted
public double getAmount() {
double total = 0.0;
Iterator it = shares.keySet().iterator();
while(it.hasNext()) { 
The whole is equal to the sum of its parts.
Share loanShare = getShare(it.next());
total = total + loanShare.getAmount();
}
return total;
}
public SharePie minus(SharePie otherShares) {
SharePie result = new SharePie();
Set owners = new HashSet();
owners.addAll(getOwners());
owners.addAll(otherShares.getOwners()); 
The difference between two
Pies
is the
 difference between each owner's share.
Iterator it = owners.iterator();
while(it.hasNext()) {
Object owner = it.next();
double resultShareAmount = getShareAmount(owner) –
otherShares.getShareAmount(owner);


result.add(owner, resultShareAmount);
}
return result;
}
public SharePie plus(SharePie otherShares) { 
The combination of two
Pies
is the
 combination of each owner's share.
//Similar to implementation of minus()
}
public SharePie prorated(double amountToProrate) {
SharePie proration = new SharePie();
double basis = getAmount(); 
An amount can be divided proportionately among all
 shareholders.
Iterator it = shares.keySet().iterator();
while(it.hasNext()) {
Object owner = it.next();
Share share = getShare(owner);
double proratedShareAmount =
share.getAmount() / basis * amountToProrate;
proration.add(owner, proratedShareAmount);
}
return proration;
}
}

Download 7,21 Mb.

Do'stlaringiz bilan baham:
1   ...   192   193   194   195   196   197   198   199   ...   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