Ik ben bezig met een setje van blogs of domain driven design. Ik wil oa discussies uitlokken omdat ik zelf eigelijk nog helemaal geen systemen heb gezien met rijke domain modellen. Ik vraag me dus af wat de gevolgen gaan worden voor het systeem en hoe eventuele problemen opgelost kunnen worden. Ik had een post in elkaar gezet maar heb van een aantal mensen gehoord dat ze het tempo erg hoog vonden, en de conclusies erg kort door de bocht (of niet onderbouwd). Dit klopt: ik wil niet dat de post erg lang gaat worden en als ze iets willen weten/het ermee oneens zijn, dan kunnen ze comments geven (verder zijn de meeste dingen al zo vaak besproken dat ik eigelijk weinig behoefte had om het nog een keer te vermelden). Ik zit nog een beetje te twijfelen hoe en of ik dit stuk ga aanpassen. Dit is trouwens wel een stuk voor mensen die al redelijk wat afweten van DDD.
-------------------------------------------------------------------------------
DDD: Can I drop my Service Layer?
Intention:
This if the first of hopefully many thoughts about Domain Driven Design.
In this post I want to explain why the Service Layer remains a usefull
construct when a rich Domain Model is used instead of an Anemic Domain
Model.
I don't think the Service Layer (PEAA), the layer under the
presentation/remoting layer, should be dropped. It is true that the
Service Layer will contain less logic because with an Anemic Domain
Model, most logic is placed in the Service Layer (see Transaction Script
in PEAA). But with a rich Domain Model (where most objects have state
<b>and</b> behaviour) the domain specific logic can be moved to the
Domain Objects (objects in the Domain Layer). So at first sight it
appears that the Service Layer is not of much use anymore, because all
domain logic will be removed from it.
But the Service Layer is still very usefull: it is a gateway to the
internals of your system and this makes it an excelent place to
coordinate (crosscutting) concerns like transactions and security.
This means that layers on top of the Service Layer, should not call
methods that change the state of the Domain Objects directly, but should
call methods in the servicelayer instead. Exposing domain objects in the
layers above some find questionable and Data Transfer Objects (DTO's)
are returned instead. I don't have a problem with both approaches (DTO's
vs Domain Objects) because they both have their pros and cons.
Another advantage of the Service Layer is that it decouples the layers
above the Service Layer, from the Domain Layer (that is below/part-of
the Service Layer), because the Service Layer also acts like a Facade:
it hides the retrieval of, and delegation to domain objects from the
layers above. You don't want this responsibility in those layers,
because it tightens the coupling. I think that decoupling will prove
itself even more valueable with rich Domain Objects because they are
likely to be refactored more often. You want to prevent that every
change in the Domain Model will lead to a change in the other layers.
And last but certainly not least is that the Service Layer is a good
place to place Application Logic. Application logic is logic that is not
part of the domain, for example returning an Excel sheet containing all
employees. The concept Excel sheet doesn't have any meaning in the
employee-domain and therefor it doesn't belong in the Domain Model.
So the Service Layer still remains a very important layer and I expect
that the interface stays the same if you use a Anemic Domain Model with
Transaction Scripts or a rich Domain Model. But what is it going to look
like if you use a rich Domain Model? If I ignore crosscutting concerns
like transactions and security (these can be added declarative) and
application logic, the Service Layer retrieves the the Domain Objects
that are going to do the work and delegates the task to them [te strakke
conclusie]
-------------------------------------------------------------------------------
DDD: Can I drop my Service Layer?
Intention:
This if the first of hopefully many thoughts about Domain Driven Design.
In this post I want to explain why the Service Layer remains a usefull
construct when a rich Domain Model is used instead of an Anemic Domain
Model.
I don't think the Service Layer (PEAA), the layer under the
presentation/remoting layer, should be dropped. It is true that the
Service Layer will contain less logic because with an Anemic Domain
Model, most logic is placed in the Service Layer (see Transaction Script
in PEAA). But with a rich Domain Model (where most objects have state
<b>and</b> behaviour) the domain specific logic can be moved to the
Domain Objects (objects in the Domain Layer). So at first sight it
appears that the Service Layer is not of much use anymore, because all
domain logic will be removed from it.
But the Service Layer is still very usefull: it is a gateway to the
internals of your system and this makes it an excelent place to
coordinate (crosscutting) concerns like transactions and security.
This means that layers on top of the Service Layer, should not call
methods that change the state of the Domain Objects directly, but should
call methods in the servicelayer instead. Exposing domain objects in the
layers above some find questionable and Data Transfer Objects (DTO's)
are returned instead. I don't have a problem with both approaches (DTO's
vs Domain Objects) because they both have their pros and cons.
Another advantage of the Service Layer is that it decouples the layers
above the Service Layer, from the Domain Layer (that is below/part-of
the Service Layer), because the Service Layer also acts like a Facade:
it hides the retrieval of, and delegation to domain objects from the
layers above. You don't want this responsibility in those layers,
because it tightens the coupling. I think that decoupling will prove
itself even more valueable with rich Domain Objects because they are
likely to be refactored more often. You want to prevent that every
change in the Domain Model will lead to a change in the other layers.
And last but certainly not least is that the Service Layer is a good
place to place Application Logic. Application logic is logic that is not
part of the domain, for example returning an Excel sheet containing all
employees. The concept Excel sheet doesn't have any meaning in the
employee-domain and therefor it doesn't belong in the Domain Model.
So the Service Layer still remains a very important layer and I expect
that the interface stays the same if you use a Anemic Domain Model with
Transaction Scripts or a rich Domain Model. But what is it going to look
like if you use a rich Domain Model? If I ignore crosscutting concerns
like transactions and security (these can be added declarative) and
application logic, the Service Layer retrieves the the Domain Objects
that are going to do the work and delegates the task to them [te strakke
conclusie]
code:
1
2
3
4
5
6
7
8
| class EmployeeManager{
private EmployeeDao employeeDao;
public void fire(long employeeId){
Employee employee = employeeDao.load(employeeId);
employee.fire();
}
} |
[ Voor 5% gewijzigd door Alarmnummer op 29-05-2006 14:15 ]