Is this correct domain model?
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: I开发者_JAVA百科s 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?
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:
- The operation relates to a domain concept that is not a natural part of an Entity or Value Object
- The interface is defined in terms of other elements in the domain model
- The operation is stateless
Los Techies has some great articles about when to create a service.
- http://lostechies.com/jimmybogard/2008/08/21/services-in-domain-driven-design/
精彩评论