且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何已被写入在外观模式的签名?

更新时间:2023-12-03 14:11:52

这是上面的例子真的好吗?我的意思是:

Is it really ok in an example above? I mean:

PersonDto findPersonByName(String name) { ... }

假设我们使用JPA,有一堆的实体,其中一个是人。
这只是一个普通的POJO,只是标注了一些JPA法宝。
是不是真的有必要写PersonDTO(假设它是一种人镜子),只是为了摆脱JPA注解?如果我的目标是回到人的信息我会简单地返回Person实例。
如果我想返回更多的信息,例如特定的人,它的轮廓,并在服务层等数据计算,我想创建像类:

Let's say we use JPA, have bunch of entities, and one of them is Person. It is just a regular POJO, just annotated with some JPA magic. Is it really necessary to write PersonDTO (assuming it is kind of Person mirror) just to get rid of JPA annotations? If my goal is to return Person information I'd return Person instance simply. If I'd like to return more info, e.g. given person, it's profile, and other data computed in service layer, I'd create class like:

public PersonInfo {
Person p;
PersonProfile;
... additional attributes required by contract...
 }