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



Download 7,21 Mb.
Pdf ko'rish
bet156/343
Sana17.11.2022
Hajmi7,21 Mb.
#867526
1   ...   152   153   154   155   156   157   158   159   ...   343
Bog'liq
Eric Evans 2003 - Domain-Driven Design - Tackling Complexity in the Heart of Software

Applying and Implementing S
PECIFICATION
Much of the value of 
SPECIFICATION
is that it unifies application functionality that may seem quite
different. We might need to specify the state of an object for one or more of these three purposes.
To validate an object to see if it fulfills some need or is ready for some purpose
1.
To select an object from a collection (as in the case of querying for overdue invoices)
2.
To specify the creation of a new object to fit some need
3.
These three uses—validation, selection, and building to order—are the same on a conceptual level.
Without a pattern such as 
SPECIFICATION
, the same rule may show up in different guises, and


3.
possibly contradictory forms. The conceptual unity can be lost. Applying the 
SPECIFICATION
pattern
allows a consistent model to be used, even when the implementation may have to diverge.
Validation
The simplest use of a 
SPECIFICATION
is validation, and it is the use that demonstrates the concept
most straightforwardly.
Figure 9.14. A model applying a 
SPECIFICATION
 for validation
class DelinquentInvoiceSpecification extends
InvoiceSpecification {
private Date currentDate;
// An instance is used and discarded on a single date
public DelinquentInvoiceSpecification(Date currentDate) {
this.currentDate = currentDate;
}
public boolean isSatisfiedBy(Invoice candidate) {
int gracePeriod =
candidate.customer().getPaymentGracePeriod();
Date firmDeadline =
DateUtility.addDaysToDate(candidate.dueDate(),
gracePeriod);
return currentDate.after(firmDeadline);
}
}
Now, suppose we need to display a red flag whenever a salesperson brings up a customer with
delinquent bills. We just have to write a method in a client class, something like this.
public boolean accountIsDelinquent(Customer customer) {
Date today = new Date();
Specification delinquentSpec =
new DelinquentInvoiceSpecification(today);
Iterator it = customer.getInvoices().iterator();
while (it.hasNext()) {
Invoice candidate = (Invoice) it.next();


if (delinquentSpec.isSatisfiedBy(candidate)) return true;
}
return false;
}

Download 7,21 Mb.

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