Monday 15 March 2010

immutability - Domain Modelling: Neither an Entity nor a Value Object -



immutability - Domain Modelling: Neither an Entity nor a Value Object -

in ddd, domain model consists of entities , value objects, when need in model neither of these?

for example, have introduced next scheduleditems<t> implementation in order encapsulate scheduling specifics:

public class scheduleditems<t> { private sorteddictionary<datetime, t> scheduleditems; public scheduleditems() { scheduleditems = new sorteddictionary<datetime, t>(); } public void scheduleitem(datetime scheduleddate, t item) { scheduleditems.add(scheduleddate, item); } public void removeitem(t item) { scheduleditems .where(x => x.value.equals(item)) .select(x => x.key) .tolist() .foreach(k => scheduleditems.remove(k)); } }

this class used couple of entities scheduling purposes.

at point, neither entity (it has no identity) nor value object (it not immutable).

one solution turn value object making immutable ('adding' or 'removing' items homecoming new instance of scheduleditems).

but necessary not associated domain? class other .net collection.

that class looks repository scheduleditems. scheduleditem entity , scheduleditems the repository add(), remove() methods.

domain-driven-design immutability value-objects

No comments:

Post a Comment