gpt4 book ai didi

architecture - 领域对象设计

转载 作者:行者123 更新时间:2023-12-04 04:01:43 24 4
gpt4 key购买 nike

在设计领域模型时,应该坚持代表问题领域的事物,并且领域模型不应包含审计信息。

所以,如果我要设计一只猫,它可能看起来像这样:

public Cat {
private Color furColor;
private Color eyeColor;
private boolean isDeclawed;
etc...
}

我永远不应该拥有像“updateDate”和“createTime”这样的属性,对吗?

现在,如果 Web 应用程序要在屏幕上显示一张猫的表格,您可能会这样:

Name    Eye Color  Claws?    Last Updated------  ---------  ------    ------------Fluffy  Green      No        10/31/2012etc...

So, if you don't keep the last update time in your domain model, how does one (properly) get that data to the page?

Obviously, I could have a poorly designed domain model, but I want to do it better.

I had considered creating an object that accepts a generic so that I could keep my domain model pristine.i.e.

public PersistableObject<T,K> {

private T domainObject;
private Date updateDate;
private User updateUser;

getters, setters, etc...
}

但是,恐怕我会遇到一些问题。

我对“域模型”和“更新日期”等进行了大量搜索...但我认为我错过了正确的术语。

有人能指出我正确的方向吗?

最佳答案

在你的场景中,我不确定我是否同意第一句话。如果您的域的一般用途包括需要显示这些日期,那么它们可以(并且很可能应该)成为您的普通域对象的一部分。

如果你想清理你的域对象,你可以简单地创建一个接口(interface)来保存那些公共(public)字段。

public interface ITrackedObject
{
DateTime LastUpdated { get; set; }
//etc....
}

public class Cat : ITrackedObject
{
public DateTime LastUpdated { get; set; }
//....
}

关于architecture - 领域对象设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11581715/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com