Naming of domain objects that act like ddd building blocks such as repositories
Asked Answered
P

2

8

When comming accross concepts within a Domain Model where there exists something that has a name and sounds like an object but overlaps with the responsiblility of one of the 5 main DDD building blocks what is the best practice for naming this object and or dealing with design which may or may not include that name or phrase in the actual implementation?

To give a more concrete example lets say that we are designing a time tracking application in the spirit of DDD and encounter something that the domain experts refer to as a "time log" which is supposed to be the log which holds punch-in and corresponding punch-out times for all employees.

With this information my initial thought is that if there were a class written called TimeLog which allowed for querying existing time entries and also for persisting new or amended time log entries that such a class is really playing the role of a DDD repository. For simplicity sake, lets assume that after various discussions and refactoring that we come to a conclusion that each time log entry is essentially it's own aggregate root and thus has the need for a corresponding repository.

Now we are left with the option of either naming our repository as TimeLog which seems more in line with the DDD concept of ubiquitous language or we could call it TimeLogEntryRepository which seems to fit the more general convention for naming Repositories after the Aggregate root that they query/persist. I'm leaning more towards the the idea of using TimeLog since it is more descriptive of the actual role that it plays in the domain model which should in turn help in communicating design to domain experts. The choice of using TimeLogEntryRepository on the other hand follows existing DDD conventions and thus would make the design easier to follow for developers. A compromise could also be to go with the TimeLog naming but to have all repositories implement an IRepository interface or inherit from a common Repository base class to help developers locate and distinguish repository classes from others that make up the domain model. The main concern I have with using a base class is that it may encourage the use of marker interfaces or a weak unnecessary base class just for the purpose of organization and not due to behavioral factors.

What is the best practice in cases like this? I can see the same type of issue perhaps happening for services as they are another piece of the typical DDD building blocks that developers typically name using a "Service" suffix such as in SomeComplexActivityService but for Entities and Value Objects this is really a non-issue. I'm especially interested to see what others may have to say that have more DDD experience under their belt.

Peavy answered 3/5, 2011 at 2:39 Comment(0)
A
6

I personally prefer TimeLog.

It's actually amazing how much easier it becomes once you switch focus to business instead of technology. Proper naming is main weapon to keep that focus sharp.

The same goes for services - instead of ApplicationRegistrationService, I use ApplicationRegistrator.

Here's quite nice article about repositories.

Atavistic answered 3/5, 2011 at 10:53 Comment(2)
I was thinking the word Registrar or Registry may make more sense but after turning to googlefight.com I was surprised to see registrator takes the cake by a wide margin. googlefight.com/…Peavy
+1, I read over the article that you linked and it turns out that they present a neat fluent interface built for repositories themselves which is pretty neat. Not sure if I want to take things that far but I can see where it has it's benefits.Peavy
E
2

I second @Arnis L. suggestion. I would also add that in respect to DDD your domain should reflect the actual UL (Ubiquitous Language) which you share with business analysist and other people that are often non technical people. So I think that you will talk with them about TimeLog and not TimeLogEntryRepository. Repository is just a pattern and it's name should not be in the naming conventions.

English answered 16/4, 2012 at 14:12 Comment(2)
I agree. You do not name the things in the domain. The others do. If they call it "TimeLog", then it is a "TimeLog". What is modelling all about? Representing the reality. They call it TimeLog, model it as TimeLog. Instead, TimeLogEntryRepository "creates" a (false?) reality instead of "modelling" it. DDD is all about discovering the reality in the expert's minds. Not imposing technical things into the business minds. Side comment: I am exploring (no conclusions yet) to use colors in the class diagrams. All the repositories will be color X and then TimeLog just would be that color.Nonconformity
@XaviMontero the problem here is that there is no such things as "service" and "repository" in the domain language. yet service and repository interfaces exist inside the domain model and services declare methods that represent some domain concepts (while repositories don't)Devonadevondra

© 2022 - 2024 — McMap. All rights reserved.