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


Example Chemical Warehouse Packer



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

Example
Chemical Warehouse Packer
There is a warehouse in which various chemicals are stored in stacks of large containers, similar to
boxcars. Some chemicals are inert and can be stored just about anywhere. Some are volatile and
have to be stored in specially ventilated containers. Some are explosive and have to be stored in
specially armored containers. There are also rules about the combinations allowed in a container.
The goal is to write software that will find an efficient and safe way to put the chemicals in the
containers.
Figure 9.16. A model for warehouse storage


We could start by writing a procedure to take a chemical and place it in a container, but instead,
let's start with the validation problem. This will force us to make the rules explicit, and it will give
us a way to test the final implementation.
Each chemical will have a container 
SPECIFICATION
:
Chemical
Container Specification
TNT
Armored container
Sand
Biological Samples
Must not share container with explosives
Ammonia
Ventilated container
Now, if we write these as 
Container Specifications
, we should be able to take a configuration of
packed containers and test to see if it meets these constraints.
Container Features
Contents
Specification Satisfied?
Armored
20 lbs. TNT
500 lbs. sand
50 lbs. biological samples
Ammonia
A method on 
Container Specification

isSatisfied()
, would have to be implemented to check
for needed 
ContainerFeatures
. For example, the SPEC attached to an explosive chemical would
look for the "armored" feature:
public class ContainerSpecification {
private ContainerFeature requiredFeature;
public ContainerSpecification(ContainerFeature required) {
requiredFeature = required;
}
boolean isSatisfiedBy(Container aContainer){
return aContainer.getFeatures().contains(requiredFeature);
}
}


Here is sample client code to set up an explosive chemical:
tnt.setContainerSpecification(
new ContainerSpecification(ARMORED));
A method on a 

Download 7,21 Mb.

Do'stlaringiz bilan baham:
1   ...   157   158   159   160   161   162   163   164   ...   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