这是正确的域模型吗?
我在书本和互联网上搜索了我的问题的答案,但没有找到。也许你可以帮助我。
假设我有这样构建的域层(我认为这是基本结构):
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;
}
//..
那么,问题是:ProductCalculator 是否可以同时使用 ProductRepository 和 ProductService? 或者也许我会走得更远:这是正确设计的域吗?
服务可以用自己的方法来解决任务吗?我正准备将 ProductCalculator 更改为 Service,但我不知道这是否正确。我只是问,在我看来,不。
最好的问候
ps 您是否有值得查看其域模型的开源项目(例如在 github 上)的链接?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当模型的概念会扭曲任何实体或值对象时,服务是合适的。
根据 Evans 的 DDD,良好的服务具有以下特征:
Los Techies 有一些关于何时创建服务的精彩文章。
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.