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


Example A Working Prototype of the Warehouse Packer



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

Example
A Working Prototype of the Warehouse Packer
Writing the optimization logic to make the warehouse packing software work is a big job. A small
team of developers and business experts have split off and have set to work on it, but they
haven't even begun to code. Meanwhile, another small team is developing the application that will
allow users to pull inventory from the database, feed it to the 
Packer
, and interpret the results.
They are trying to design for the anticipated 
Packer
. But all they can do is mock up a UI and work
on some database integration code. They can't show the users an interface with meaningful
behavior to get good feedback. For the same reason, the 
Packer
team is working in a vacuum
too.
With the domain objects and 
SERVICE
interface made in the warehouse packer example, the
application team realizes they could build a very simple implementation of a 
Packer
that could
help the development process move along, allowing work to go forward in parallel and closing the
feedback loop, which only reaches full effect with a working end-to-end system.
public class Container {
private double capacity;
private Set contents; //Drums
public boolean hasSpaceFor(Drum aDrum) {
return remainingSpace() >= aDrum.getSize();
}
public double remainingSpace() {
double totalContentSize = 0.0;
Iterator it = contents.iterator();
while (it.hasNext()) {
Drum aDrum = (Drum) it.next();
totalContentSize = totalContentSize + aDrum.getSize();
}
return capacity – totalContentSize;
}
public boolean canAccommodate(Drum aDrum) {
return hasSpaceFor(aDrum) &&
aDrum.getContainerSpecification().isSatisfiedBy(this);
}
}
public class PrototypePacker implements WarehousePacker {
public void pack(Collection containers, Collection drums)
throws NoAnswerFoundException {
/* This method fulfills the ASSERTION as written. However,
when an exception is thrown, Containers' contents may
have changed. Rollback must be handled at a higher
level. */
Iterator it = drums.iterator();
while (it.hasNext()) {
Drum drum = (Drum) it.next();
Container container =
findContainerFor(containers, drum);


container.add(drum);
}
}
public Container findContainerFor(
Collection containers, Drum drum)
throws NoAnswerFoundException {
Iterator it = containers.iterator();
while (it.hasNext()) {
Container container = (Container) it.next();
if (container.canAccommodate(drum))
return container;
}
throw new NoAnswerFoundException();
}
}
Granted that this code leaves a lot to be desired. It might pack sand into specialty containers and
then run out of room before it packs the hazardous chemicals. It certainly doesn't optimize
revenues. But a lot of optimization problems are never solved perfectly anyway. This
implementation does follow the rules that have been stated so far.

Download 7,21 Mb.

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