Message-based domain object collaboration <p>Recently, i was thinking about how to use message to implement the domain object collaboration. And now i have some thoughts:</p> <ol> <li>Each domain object will implement an interface if it want to response one message;</li> <li>Each domain object will not depend on any other domain objects, that means we will not have the Model.OtherModel relation;</li> <li>Each domain object only do the things which only modify itself;</li> <li>Each domain object can send a message, and this message will be received by any other domain objects which are care about this message;</li> </ol> <p>Totally, the only way of collaboration between domain objects is message, one domain object can send any messages or receive any messages as long as it need.</p> <p>When i learn Evans's DDD, i see that he defines the aggregate concept in domain, i think aggregate is static and not suitable for objects interactions, he only focused on the static structure of objects or relationship between objects. In real world, object will interact using messages, not by referencing each other or aggregating other objects. In my opinion, all the objects are equal, that means they will not depend on any other objects. For about how to implement the functionality of sending messages or receive messages, i think we can create a EventBus framework which is specially used for the collaboration of domain object. We can mapping the <strong>event type</strong> to the <strong>subscriber type</strong> in a dictionary. The key is event type, the value is a list of subscriber types. When one event is raised, we can find the corresponding subscriber types, and get all the subscriber domain objects from data persistence and then call the corresponding handle methods on each subscriber.</p> <p>For example:</p> <pre><code>public class EventA : IEvent { } public class EventB : IEvent { } public class EventC : IEvent { } public class ExampleDomainObject : Entity&lt;Guid&gt;{ public void MethodToRaiseAnExampleEvent() { RaiseEvent(new EventC()); } } public class A : Entity&lt;Guid&gt;, IEventHandler&lt;EventB&gt;, IEventHandler&lt;EventC&gt; { public void Handle(EventB evnt) { //Response for EventB. } public void Handle(EventC evnt) { //Response for EventC. } } public class B : IEventHandler&lt;EventA&gt;, IEventHandler&lt;EventC&gt; { public void Handle(EventA evnt) { //Response for EventA. } public void Handle(EventC evnt) { //Response for EventC. } } </code></pre> <p>That's my thoughts. Hopes to hear your words.</p>