SomePersistenceService

SomePersistenceService

本文介绍了是否“保存”?方法属于企业域实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有使用任何ORM。因此,我在争论保存方法实际上是属于业务领域实体还是应该在将要交付给业务领域实体进行保存的某些服务中抽象化?



  class员工
{
字符串名称;
DateTime出生;

GetAge()
{

}

Save()
{
}

}

OR



class Employee
{
string Name;
DateTime出生;

GetAge()
{

}


}

SomePersistenceService
{
保存(员工雇员)
{
}
}


解决方案

由于此问题被标记为域驱动设计,因此您将需要一个存储库来为您完成。






只需将SomePersistenceService重命名为EmployeeRepository。因此,使用第二个选项可以使您走上正确的道路。 在将要移交给业务域实体的某些服务中摘要化 在域驱动设计中称为存储库



存储库是一种伪装您的数据存储为集合的方式。因此,它具有添加删除之类的方法,而不是保存删除


I am not using any ORM. So I am having a debate whether "Save" method actually belongs to a Business Domain entity or should be abstracted in some service that will be handed over the Business Domain Entity for saving ?

e.g.

class Employee
{
    string Name;
    DateTime Birth;

    GetAge()
    {

    }

    Save()
    {
    }

}

OR

class Employee
{
    string Name;
    DateTime Birth;

    GetAge()
    {

    }


}

SomePersistenceService
{
    Save(Employee emp)
        {
        }
}
解决方案

Since this question is tagged with 'domain-driven-design', you'll need a repository to do it for you.


Just rename SomePersistenceService to EmployeeRepository. So you were on the right track with your second option. "abstracted in some service that will be handed over the Business Domain Entity" is called repository in domain driven design

A repository is a way to pretend that your datastore is a collection. So it has methods like Add and Remove instead of Save and Delete.

这篇关于是否“保存”?方法属于企业域实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 13:27