dimanche 30 mai 2021

DDD - How to design filesystem domain

I am creating a system in which the domain is a file system. There are entities such as catalog and document. Each document must exist in some directory and each directory has a parent (excluding root catalog). What should a properly created aggregate for this system look like?

class Catalog {
   private Catalog parent;
   private List<Document> documents;
   ...
}

class Document {
   private Catalog catalog;
   ...
}

The approach presented above seems to me the best from an architectural point of view. One of the DDD principleis that an aggregate must be loaded and saved as a whole. Therefore, the presented example is impossible to implement in practice, because it required to load the entire tree of files from the database.

class Catalog {
   private CatalogID parent;
   private List<DocumentID> documents;
   ...
}

class Document {
   private CatalogID catalog;
   ...
}

Another approach is to store IDs only, rather than objects in entities. However, in this case, I cannot access the related entities.

For example, consider a method that checks if a document name is unique within a given directory.

class Catalog {
   private CatalogID parent;
   private List<DocumentID> documents;
   
   public bool IsNameUnique(string name) {
      foreach (document in documents) {
        if (document.Name == name) return true; <-- docuemnt is only ID, not reference
      }
      return true;
   }
}

I can't get the document name because I only store the ID instead of the entity reference.

What approach should I choose to solve this problem in the best way? Thanks in advance for your help.

Aucun commentaire:

Enregistrer un commentaire