业务对象应该包含对象还是引用?
业务对象是否应该包含对其他对象的引用(如 id 字段中引用另一个数据库记录)或者是否应该具有实际对象的实例。
例如:
public class Company
{
public int Id { get; set; }
public CompanyStatus Status { get; set; }
}
或
public class Company
{
public int Id { get; set; }
public int Status { get; set; }
}
Should a business object contain a reference to other objects (as in the id field references another database record) or should it have an instance of the actual objects.
For example:
public class Company
{
public int Id { get; set; }
public CompanyStatus Status { get; set; }
}
or
public class Company
{
public int Id { get; set; }
public int Status { get; set; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据我的理解,它应该包含对接口的引用,而不是具体的类。
假设您的示例中 CompanyStatus 的具体实现是一个类而不是枚举。
From my understanding, it should contain references to interfaces, not concrete classes.
Assuming that the concrete implementation of CompanyStatus in your example was a class and not an enum.
当以面向对象的方式创建业务层对象时,您应该直接使用对象。
在您的示例中,
int Status
是否引用存储在某处的 CompanyStatus 对象的 Id? 在这种情况下,感觉这更像是数据层的问题。 通常最好避免将数据层与业务层混合。When creating Business Layer objects in an OO fashion, you should be using objects directly.
In your example, does
int Status
refers to the Id of a CompanyStatus object stored somewhere? In that case, it really feels like that's more of a data layer concern. It is usually best to avoid mixing your data layer with your business layer.如果您谈论的是 C#,那么聚合一个对象意味着您正在存储对其的引用。
If you're talking about C#, then aggregating an object means you're storing a reference to it.
这取决于数据。 有些数据应该存储为原始对象的副本,有些应该作为引用。
It depends on the data. Some data should be stored as a copy of the original object, some should be a reference.