Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Repository class in DDD

I am trying to follow DDD and I have a Question class and a Feedback class (among others). I want to be able to count the number of questions, number of feedbacks and many other things which is considered meta operations.

Should such "meta" methods be in the same repository as the other methods belonging to the class, or should they be in a MetaRepository where you have different meta methods that queries the database (in this case all classes will be mixed)?

like image 801
LuckyLuke Avatar asked Feb 15 '12 21:02

LuckyLuke


2 Answers

Nothing in DDD prohibits having more than one repository per aggregate. You can simply have one repository for basic queries and lifecycle methods (IQuestionsRepository) and a separate repository for what you call 'meta' or 'statistics' purposes (IQuestionsStatistics). This works very well for a larger domains where following one-repository-per-aggregate principle may result in 'method explosion' and SRP violation. Following DDD should not go against basic OOP principles.

like image 74
Dmitry Avatar answered Oct 19 '22 23:10

Dmitry


To me, each repository is responsible for counting its elements, it's one method among getById, getAll... (standard methods).

like image 22
Francois Avatar answered Oct 19 '22 23:10

Francois