类,对象,实体:有什么区别? [英] Class, Object, Entity: What's the difference?

查看:2856
本文介绍了类,对象,实体:有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也看到了其他术语:实体对象,价值对象等。我还应该知道其他术语,这些术语是指什么?

I also see other terms as well: Entity Object, Value Object, etc. Are there other terms out there that I should know, and what do these terms refer to?

通过阅读代码可以识别它们之间的差异(如果有的话)吗?

Can the differences between them, if any, be identified by reading code?

推荐答案

类是用于创建对象的模板。并非所有OO语言都使用类(请参阅Self,Javascript)。通常,类被实现为对象。

A class is a template for creating objects. Not all OO languages use classes (see Self, Javascript). Typically classes are implemented as objects.

对象是与作用于该数据的函数(称为方法)打包在一起的数据包。调用类的构造函数为对象分配内存并初始化其成员变量。

An object is a bundle of data that is packaged with functions that act on that data (called methods). Calling a class's constructor allocates memory for the object and initializes its member variables.

实体是一个对象,表示具有系统有兴趣跟踪的标识的对象。典型的例子是客户和账户。

An entity is an object that represents something that has an identity that the system is interested in tracking. Typical examples are Customers and Accounts.

值对象是一个值,它没有标识,并且具有相同值的两个实例被认为是相同的。典型的例子是货币金额,地点,支付类型。

A value object is a value, it doesn't have an identity, and two instances with the same value are considered to be identical. Typical examples are monetary amounts, locations, payment types.

数据传输对象用于传递大量数据。通常,它们在分布式系统中用于将数据作为捆绑发送,以避免重复的网络呼叫。数据传输对象没有身份(或者没有期望它们应该有),它们只是数据的容器。

A data transfer object is used for passing a bunch of data around. Typically they're used in distributed systems to send data as a bundle in order to avoid repeated network calls. Data transfer objects have no identity (or there is no expectation they should have any), they are just containers for data.

通常你可以分辨实体和值之间的区别对象,因为实体具有可识别的标识,系统关注创建,存储和更改它们。在对象映射到某个数据库的情况下,实体的主键可以是某种复合自然键或人工键,而值对象则按值进行比较。

Generally you can tell the difference between entities and value objects because entities have a recognizable identity, and the system is concerned with creating them, storing them, and changing them. In cases where objects map to some database, entities have primary keys that are either some kind of composite natural key or an artificial key, while value objects are compared by value.

这篇关于类,对象,实体:有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆