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



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

Invoice Specification
and is implemented in the
Delinquent Invoice Specification
subclass:
public String asSQL() {
return


"SELECT * FROM INVOICE, CUSTOMER" +
" WHERE INVOICE.CUST_ID = CUSTOMER.ID" +
" AND INVOICE.DUE_DATE + CUSTOMER.GRACE_PERIOD" +
" < " + SQLUtility.dateAsSQL(currentDate);
}
S
PECIFICATIONS
mesh smoothly with 
REPOSITORIES
, which are the building-block mechanisms for
providing query access to domain objects and encapsulating the interface to the database (see
Figure 9.15).
Figure 9.15. The interaction between 
REPOSITORY
 and 
SPECIFICATION
Now this design has some problems. Most important, the details of the table structure have leaked
into the 
DOMAIN LAYER
; they should be isolated in a mapping layer that relates the domain objects
to the relational tables. Implicitly duplicating that information here could hurt the modifiability and
maintainability of the 
Invoice
and 
Customer
objects, because any change to their mappings now
have to be tracked in more than one place. But this example is a simple illustration of how to keep
the rule in just one place. Some object-relational mapping frameworks provide the means to
express such a query in terms of the model objects and attributes, generating the actual SQL in
the infrastructure layer. This would let us have our cake and eat it too.
When the infrastructure doesn't come to the rescue, we can refactor the SQL out of the expressive
domain objects by adding a specialized query method to the 
Invoice Repository
. To avoid
embedding the rule into the 
REPOSITORY
, we have to express the query in a more generic way, one
that doesn't capture the rule but can be combined or placed in context to work the rule out (in this
example, by using a double dispatch).
public class InvoiceRepository {
public Set selectWhereGracePeriodPast(Date aDate){
//This is not a rule, just a specialized query
String sql = whereGracePeriodPast_SQL(aDate);
ResultSet queryResultSet =


SQLDatabaseInterface.instance().executeQuery(sql);
return buildInvoicesFromResultSet(queryResultSet);
}
public String whereGracePeriodPast_SQL(Date aDate) {
return
"SELECT * FROM INVOICE, CUSTOMER" +
" WHERE INVOICE.CUST_ID = CUSTOMER.ID" +
" AND INVOICE.DUE_DATE + CUSTOMER.GRACE_PERIOD" +
" < " + SQLUtility.dateAsSQL(aDate);
}
public Set selectSatisfying(InvoiceSpecification spec) {
return spec.satisfyingElementsFrom(this);
}
}
The 
asSql()
method on 

Download 7,21 Mb.

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