Reputation: 1335
I have searched in my books and in the Internet answer to my question but I didn't finded. Maybe you could help me.
Let's suppose that I have domain layer counstructed in this way (I think it is basical stucture):
Product
IProductRepository
IProductService
ProductCalculator
class ProductService : IProductService
//..
public List<Product> GetSimilarProducts(productId) {
// body of this method is just an example, it doesn't have sense
var product = repo.FindById(productId)
repo.FindBySimilarName(product.Name);
// some more logic
// and more
return similarsProducts;
}
//..
class ProductCalculator : ICalculate
//..
private Product _p;
public ProductCalculator(Product p) {
_p = p;
}
public double Calculate() {
// logic..
// calling repo
// calling services
// calling own class methods
return result;
}
//..
So, the question is: Does ProductCalculator can use both ProductRepository and ProductService? Or maybe I go even farther: Is this correct designed domain?
Can service use his own methods to solve the task? Im heading to change ProductCalculator into Service but I dont know is this correct. Im just asking, in my opinion, no.
Best regards
ps Have you got links to an open source projects (eg. on github) that are worth to look at theirs domain model?
Upvotes: 0
Views: 145
Reputation: 2380
When concepts of the model would distort any Entity or Value Object, a Service is appropriate.
From Evans’ DDD, a good Service has these characteristics:
Los Techies has some great articles about when to create a service.
Upvotes: 4