I'm having an issue with naming of my types, generally it applies to all of my projects.
I'm working with CQRS and many times i have different layers of my application that refer to similar 'context' of a data. For example i have a Player context which is spread across query model, write model, domain model etc.
Basically my question is that if some class/struct/data type is referring to specifically 'Query' type, should i name it as PlayerQuery or QueryPlayer.
From my understanding the 'PlayerQuery' implies that it is a query of a player data, on the other hand 'QueryPlayer' implies some kind of 'Query' behavior.
It has been quite a while when i started coding but i still struggle with properly naming things.
It feels like the 'PlayerQuery' is better approach here. Are there any books or online resources where i could tackle this issue? Thanks much
It has been quite a while when i started coding but i still struggle with properly naming things.
A great quote that is relevant here 😋 :
There are only two hard things in Computer Science: cache invalidation and naming things.
-- Phil Karlton
You are having this problem because you are trying to approach the problem with a CRUD
mindset, whereas CQRS (or CQS) advocates focusing on the actual interaction. Even when different parts of the application share player context, the reason for its usage will be different.
As examples, you will be:
In each of these interactions, you should take the interaction itself as a cue to name the Query/Command/DTO object.
So the data class names could be:
An improvement would be to suffix each class name with the type of object:
The best implementation would be to combine the interaction with the type of object:
The most important thing is, once you choose a convention (like Detail instead of Item or Row), be consistent in its usage all over the code.