I have a "MyUnits" application that let's manage Units (like meters, kilograms, pounds, miles, km/h...). The model is complex, it supports unit compatibilities, operations, conversions, etc.
I have another application (MyApp) that will need to use "units", so I want to make it use my "Units" application.
What I thought is to have a "Units" service (webservice) UnitService
that consumes and returns a Unit DTO UnitDTO
.
In MyApp, I have this model:
Operand
value: float
unit: UnitDTO
OperationAdd
operand1: Operand
operand2: Operand
execute()
The problem: in OperationAdd.execute()
, I need to check that units are compatibles (for example).
So either:
UnitDTO
has a method that will callUnitService::areCompatible
, but that is wrong! How a DTO (that should only contain data) knows UnitService which is a webservice! It shouldn'tOperationAdd.execute()
callsUnitService::areCompatible
, but that is wrong! How OperationAdd (an entity) knows UnitService which is a webservice! It shouldn'tor I have a
OperationService
that does the work (and that can call services) but myOperation
entities would be like data containers, entities with no methods, and that's not really what DDD is about
I don't want anemic entities, but in the case where I have an entity that uses a service, how can I do?
And: am I wrong thinking that UnitDTO can be used as a VO?