0

I am a beginner with DDD and I try to model elegantly in C# the next scenario:

  1. A template that basically has only a name property on it and a list of items that have to be executed in a specific order.

    public class Template
    {
        public string Name { get; set; }
        public List<Item> Items { get; set; }
    }
    
    public class Item
    {
        public string Name { get; set; }
        public int Order { get; set; }
    }
    
  2. A type called Profile.

    public class Profile
    {
        public string Name { get; set; }
    }
    

The profile class is intended to say

  • I am using template A to know what items I have and in what order
  • If template A changes, then I am using the new version because I don't want to keep a clone of the list template A had.
  • If I am deleted then the template is not affected in any way
  • If I am created then I require a template
  • I can be looked after by my name only

This looks like the aggregate root would be the template, which would have a list of Items and a list of Profiles. But I feel that searching by the name of the profile is requiring me to search all the templates that have a profile with the given name. Somehow, coming from a CRUD background, it seems a high price to pay. Also, the profile is the one that uses the template and having the template know about profiles that use it, seems wrong.

How do you model this? What should be the aggregate root here? Is more than one? How do you perform the search if you want to use it from UI?

Ilya Palkin
  • 14,687
  • 2
  • 23
  • 36
Gradinariu Cezar
  • 553
  • 1
  • 5
  • 12
  • Is there anything else to a `Profile` than a template name, so that we can have a little more context ? If not, I can't see the point of having a `Profile` (or a template) at all. – guillaume31 Aug 03 '15 at 12:17

2 Answers2

5

Don't. Do not start meta-modeling and over-abstracting when you need to learn DDD. It is a really bad idea, as it will focus your attention on things that have nothing to do with learning DDD, will distract you, and will lead you to making bad decisions.

You need to start with solving concrete problems. Abstractions need to come from the concrete solutions. After you have implemented (at least three of) them, it is time to look at abstractions

Stephan Eggermont
  • 15,847
  • 1
  • 38
  • 65
2

Neither Profile or Template can be nested within the other aggregate, they need to exist as separate aggregates. It sounds as though the Profile needs to keep a reference to which Template it is using. Therefore, I'd include a reference to the template by id (Template.Name).

public class Template
{
    public string Name { get; set; }

    public List<Item> Items { get; set; }
}

public class Item
{
    public string Name { get; set; }

    public int Order { get; set; }
}

public class Profile
{
    public string Name { get; set; }

    public string TemplateName { get; set; }
}
Adrian Thompson Phillips
  • 6,893
  • 6
  • 38
  • 69
  • 2
    You could also argue that `Item` should be an AR of it's own and `Template` would only hold onto a collection of `TemplateItem` value objects to order the items. If you think about it, there's no **command** use case that requires a template to be loaded with all it's items. ARs are not meant to be tweaked for queries, but for processing commands. – plalx Jul 31 '15 at 17:45
  • Thanks guys, I have implemented using this approach and I liked the argument that AR are first for processing commands, not queries. That cleared a lot of my doubts. – Gradinariu Cezar Aug 03 '15 at 04:45