对于只包含数据而不包含逻辑的类,是否有一个标准术语?

发布于 2024-08-04 21:39:23 字数 323 浏览 2 评论 0原文

我正在寻找一种标准方法来与其他程序员沟通,类本质上只是一个数据容器。

以这个简单的 User 类为例:

class User
{
    public string userName { get; set; }
    public string passPhrase { get; set; }
    public Role role { get; set; }
}

“该组件使用 User 类,它只是一个(在此处插入)类。”

我想说“数据模型”,但我认为这太宽泛了。描述为数据模型的类通常具有逻辑。

I'm looking for a standard way to communicate to another programmer that a class is a essentially just a data container.

Take this simple User class for example:

class User
{
    public string userName { get; set; }
    public string passPhrase { get; set; }
    public Role role { get; set; }
}

"That component makes use of the User class, which is just a (insert here) class."

I want to say "data model", but I think that's too broad. Classes described as data models often have logic.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

盗琴音 2024-08-11 21:39:23

有时这些被称为 DTO——数据传输对象。

Sometimes these are called DTOs - Data Transfer Objects.

瞎闹 2024-08-11 21:39:23

POD - 普通旧数据

POD - Plain Old Data

|煩躁 2024-08-11 21:39:23

怎么样:struct

How about: struct ?

z祗昰~ 2024-08-11 21:39:23

在这种情况下,“值对象”比“数据传输对象”更精确。值对象仅包含值;数据传输对象还应该实现一种方法,用于将数据传输到自身或从其他实体传输数据。 “Bean”也是一个公认的术语,特别是在 Java 圈内。

"Value object" is more precise in this case than is "Data Transfer Object". A value object contains just values; a Data Transfer Object additionally should implement a method for transferring that data to or from itself to or from some other entity. "Bean" is also an accepted term particularly within Java circles.

玉环 2024-08-11 21:39:23

POXO - 普通旧 X 对象,其中 X 是您选择的语言。你的情况看起来像 C#,所以这是一个 POCO:普通旧 C# 对象。

POXO - Plain Old X Object, where X is the language of your choice. Your case, seems like C#, so that's a POCO: Plain Old C# Object.

酸甜透明夹心 2024-08-11 21:39:23

在 Java 中,只有属性和每个属性的 getter/setter 的类称为 bean 或 POJO(普通旧 Java 对象)

In Java a class with only properties and getters/setters for each property is called a bean or POJO (Plain Old Java Object)

橘味果▽酱 2024-08-11 21:39:23

数据传输对象通常称为 DTO。

Data Transfer Object more commonly referred to as a DTO.

躲猫猫 2024-08-11 21:39:23

这不是标准的,但我经常将“Info”后缀附加到类名上,以表明该类仅用于存储和传输信息。因此,我会将您的 User 类更改为 UserInfo

UserData 也可以工作,就像顶部的“不要向这个该死的东西添加任何方法”注释一样。

This isn't standard, but I often attach the "Info" suffix to a class name to indicate that the class is just meant to store and transfer information. So I would change your User class to UserInfo.

UserData would work, too, as would a "don't add any methods to this damn thing" comment at the top.

失与倦" 2024-08-11 21:39:23

数据传输对象可能是正确的,具体取决于意图。它本质上是一个容器,但“容器”是重载的,一般指集合类型。

值对象可以有行为,但是如果您有两个独立创建的具有相同字段值的值对象,并且它们可以被视为等效(例如记录的身份并不重要),您可以说您拥有的是一个值对象。但通常值对象在不可变时是最好的。

当设计中有大量数据传输对象时,该设计有时被轻蔑地称为贫血域模型。

Data Transfer Object may be correct, depending on the intent. It's essentially a container, but "container" is overloaded and generally refers to collection types.

Value Objects can have behavior, but if you have two independently created value objects with the same field values, and they can be treated as equivalent (e.g. the identity of the record doesn't matter), you could say that what you have is a value object. But usually Value Objects are best when immutable.

When there are a lot of Data Transfer Objects in a design, the design is sometimes pejoratively referred to as an Anemic Domain Model.

你没皮卡萌 2024-08-11 21:39:23

来自 Haskell 简介

“这样的类型通常称为元组类型,因为它本质上只是其他类型的笛卡尔积。”

From A Gentle Introduction to Haskell

"A type like this is often called a tuple type, since it is essentially just a cartesian product of other types."

活雷疯 2024-08-11 21:39:23

数据对象、数据传输对象、DTO

Data Object, Data Transfer Object, DTO

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文