Java数据传输对象命名约定?

编程入门 行业动态 更新时间:2024-10-27 22:23:03
本文介绍了Java数据传输对象命名约定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

鉴于这种情况,你有一个客户端库传递给API的传输对象(POJO只有getter / setter),命名传输对象的最佳方法是什么?

Given this scenario where you have "transfer objects" (POJO's with just getters/setters) which are passed by a client library to your API, what is the best way to name the transfer objects?

package com.x.core; public class Car { private String make; private String model; public Car(com.x.clientapi.Car car) { this.make = car.getMake(); this.model = car.getModel(); } }

在此示例中,您的主类和转移对象都是名称 Car 。它们有不同的包装,但我认为拥有相同的名称令人困惑。是否有关于如何命名传输对象的最佳实践?

In this example your main class and your transfer object both have the name Car. They are in different packages but I think it's confusing to have the same name. Is there a best practice on how to name the transfer objects?

推荐答案

我通常将'DTO'添加到类的末尾名称以及将所有DTO放在他们自己的包中。在您的示例中,我将其称为com.x.core.dto.CarDTO。

I generally add 'DTO' to the end of the Class name as well as place all the DTO's in their own package. In your example I would call it com.x.core.dto.CarDTO.

更多推荐

Java数据传输对象命名约定?

本文发布于:2023-07-27 11:42:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1222270.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据传输   对象   Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!