0
votes

I have tried to find a solution to this naming problem, but I could not find a similar usage anywhere on the web. It could be either we have a design flow in the domain model, or we simply don't use the appropriate name for so called "ValueObjects".

Please read below..

We use Domain Driven Design with CQRS pattern. Below is how the domain model has been designed.

enter image description here

P.S Not related but for your information, our application uses ASP.NET MVC and the Controller comminicate withe the Service Layer. DTOs (Data Transfer Objects) are passed in/out to the MVC Controllers, which is not in the above diagram.

The problem is that we don’t use the "ValueObject" correctly. According Martin Fowler’s definition our ValueObjects are not a true representation of a ValueObject. http://martinfowler.com/bliki/ValueObject.html

For example our ValueObjects have an identity.

public class NoteValue 
{
    public int Id { get; set; }
    public string NoteName { get; set; }
    public string NoteNumber { get; set; }
    public DateTime NotExpiry { get; set; }
}

These ValueObjects simply carry data between the Commands, AggregateRoots and Domain Entities. For example AggregateRoot simply creates ValueObjects based on the Domain Entities, and return those ValueObjects to the Command Layer.

Below is not the complete implementation. Just a simple example to show the interaction

AggregateRoot extension method:

 private static IList<NoteValue> ToValueObject(this ICollection<Note> source)
 {
    var values = new List<NoteValue>();
    if (source != null)
         source.ForEach(i => values.Add(i.ToValueObject()));

    return values;
 }

AggregateRoot :

 Public IList<NoteValue> GetNotesValues()
 {
     return this._notes.ToValueObject();        
 }  

Command :

  var motesValues = notesAggregate.GetNotesValues();

We are struggling to find an appropriate name for these so called “ValueObjets”. They don't seem to be DTOs either and also we want to be able to differentiate from the DTOs that are used in the Services layer. Specifically we want to know an appropriate name that we can call for these types of objects (ValueObjects). Any thoughts greatly appreciated.

1
Why do you convert between Note and NoteValue at all? Why not just expose the Note object directly to the encapsulating application service (what I think you call command)?eulerfx
Why do you have both Aggregate Root and Repositories? Usually, once you start thinking along the lines of Aggregate Roots, Repositories tend to either disappear or conflate with the ARs.Mark Seemann
While you state that this is related to DDD, all I see is infrastructure architecture. Where's the domain model? DDD is about modeling the Domain, not about any particular flavour of architecture. The patterns in the blue book are just (good) suggestions - you don't have to implement them all.Mark Seemann
Basically, CQRS-style architecture tends to treat Commands as self-contained messages (DTOs) that are then handled by CommandHandlers. I'm not saying that this is the only way to do CQRS, but from the diagram above, it seems to me that these two roles (Commands and CommandHandlers) have been conflated in your Command role. My intuition tells me that this is what's causing problems.Mark Seemann
@eulerfx sorry took while to get back. I have lot reading to especially Mark has some really good points that I need to look into. In regards to converting Domain (i.e Note) to Value (i.e NoteValue) - When the repo return the domain object, in some cases, AR doesn't need a fully fledged domain object. This is why we convert DO to an intermediate object (VO) which contains only the properties we need.Spock

1 Answers

3
votes

I don't know if this answers your questions but I might hopefully point you in the right direction.

There is a very good talk about Value Objects by Dan Berg Johnsson: http://www.viddler.com/v/6939b23

Also have a look at Vaughn Vernon's papers on Effective Aggregate Design: http://dddcommunity.org/library/vernon_2011

All in all DDD (especially when applying CQRS on the architectural level) takes some time to grasp. Be patient, read, learn, and join the DDD/Cqrs Google group