简体   繁体   English

实体和类有什么区别?

[英]What's the difference between entity and class?

实体是类的实例吗?

A class is a template for an object (among other things), and is a very general concept.是对象(除其他外)的模板,是一个非常通用的概念。

An entity has more semantic significance and is usually tied to a concept (possibly about a real object for example, an Employee or a Student or a Music Album ) and is linked to business logic.实体具有更多的语义意义,通常与概念相关(可能与真实对象有关,例如,员工学生音乐专辑)并与业务逻辑相关联。

Entities are usually used to establish a mapping between an object and to a table in the database.实体通常用于在对象和数据库中的表之间建立映射。 Entities are also known as domain objects.实体也称为域对象。 Like I mentioned before, entities will be used in situations where there is business logic and as such it hold information about the system (or part of the system) that it is modeling.就像我之前提到的,实体将用于存在业务逻辑的情况,因此它保存有关它正在建模的系统(或系统的一部分)的信息。

To add one more point再增加一点

Class is a syntactic ie A set or category of things having some property or attribute in common and differentiated from others by kind, type, or quality.是一种句法,即一组或类别的事物,具有某些共同的属性或属性,并通过种类、类型或质量与其他事物区分开来。

Entity is a semantic ie relating to meaning in language or logic.实体是一种语义,即与语言或逻辑中的意义有关。 An en tity is something that ex ists in itself, actually or potentially, concretely or abstractly, physically or not.tity是什么,本身派,实际或潜在的,具体或抽象,身体或没有。 It needs not be of material existence.它不需要物质存在。

Object is a in-memory value referenced by identifier, it is an instance of a Class. Object是一个由标识符引用的内存中的值,它是一个类的实例。

在此处输入图片说明

An entity usually refers to something, anything really, that has a unique and separate existence.实体通常是指具有独特和独立存在的事物,实际上是任何事物。

In software development this word is almost only used to denote that one instance is different from another instance and they are independent of each other.在软件开发中,这个词几乎只用来表示一个实例与另一个实例不同,它们彼此独立。

A class , on the other hand, defines or contains the definition of an object .,在另一方面,限定或包含一个对象的定义。 Once that object is constructed based on the definition, then you get your instance or object instance .根据定义构造该对象后,您将获得实例对象实例

Short -- yes.简短——是的。

Entity is more a concept from real world.实体更多是来自现实世界的概念。 Instance (alias is object) -- from programming world.实例(别名是对象)——来自编程世界。

In programming world we also has an "entity" concept, but here it's more a child of an instance.在编程世界中,我们也有一个“实体”概念,但在这里它更像是一个实例的孩子。 So any entity is a child of instance.所以任何实体都是实例的孩子。 Also entity has it's links to other things but programming -- for example, as people said -- entity can have table in DB.实体也有它与其他事物的链接,但编程 - 例如,正如人们所说 - 实体可以在数据库中有表。 Instance can't have table in DB.实例不能在数据库中有表。 As instance is always connected to class.因为实例总是连接到类。

An object is an entity that has state, behavior, and identity.对象是具有状态、行为和身份的实体 The structure and behavior of similar objects are defined in their common class.相似对象的结构和行为在它们的公共类中定义。 The terms instance and object are interchangeable.术语实例对象可以互换。

From Grady Booch book .来自Grady Booch 的书

So we could say, that entity, object and class instance are interchangeable.所以我们可以说,实体、对象和类实例是可以互换的。

Entities实体

An entity is a lightweight persistence domain object.实体是一个轻量级的持久域对象。 Typically an entity represents a table in a relational database, and each entity instance corresponds to a row in that table.通常,实体代表关系数据库中的一个表,每个实体实例对应于该表中的一行。 The primary programming artifact of an entity is the entity class, although entities can use helper classes.实体的主要编程工件是实体类,尽管实体可以使用辅助类。 The persistent state of an entity is represented either through persistent fields or persistent properties.实体的持久状态通过持久字段或持久属性表示。 These fields or properties use object/relational mapping annotations to map the entities and entity relationships to the relational data in the underlying data store.这些字段或属性使用对象/关系映射注释将实体和实体关系映射到底层数据存储中的关系数据。

Entity classes have a stereotype of entity.实体类具有实体的构造型。 An entity class is essentially an object wrapper for a database table.实体类本质上是数据库表的对象包装器。 The attributes of an entity are transformed to columns on the database table.实体的属性被转换为数据库表上的列。 Entities can have various data maintenance operations such as read, insert, modify, remove, readmulti (read multi reads multiple records from a table based on a partial key).实体可以有多种数据维护操作,例如读取、插入、修改、删除、读取多(读取多基于部分键从表中读取多条记录)。

Entities can have attributes, operations, dependencies, inherits relations, and aggregations.实体可以具有属性、操作、依赖关系、继承关系和聚合。 A set of rules is associated with each of these constructs.一组规则与这些结构中的每一个相关联。

  • Entity class rules实体类规则
    Entities must have at least one attribute.实体必须至少具有一个属性。 The exception is if the entity is a subclass of another entity, in which case the entity must have no attributes.例外情况是实体是另一个实体的子类,在这种情况下,实体必须没有属性。 Entities are not allowed to aggregate other classes.实体不允许聚合其他类。

  • Entity attributes实体属性
    Entity attributes correspond to columns with the same name on their associated database table.实体属性对应于其关联数据库表上具有相同名称的列。

  • Entity operations实体操作
    Entity operations can be divided into two categories as determined by their stereotype: database and non-database operations.实体操作根据其构造型可以分为两类:数据库操作和非数据库操作。

  • Entity outputs实体输出
    Entity classes are transformed into classes with operations and no attributes.实体类被转换成有操作而没有属性的类。 The attributes from the entity in the input meta-model are transformed into one or more structs.来自输入元模型中实体的属性被转换为一个或多个结构。

  • Entity class options实体类选项
    The options available for entity classes are entity class abstracts, allow optimistic locking, audit fields, enable validation, last updated field, No Generated SQL, and replace superclass.实体类可用的选项是实体类抽象、允许乐观锁定、审计字段、启用验证、上次更新字段、未生成 SQL 和替换超类。

  • Optimistic locking for concurrency control并发控制的乐观锁
    Using optimistic locking for concurrency control means that more than one user can access a record at a time, but only one of those users can commit changes to that record.使用乐观锁定进行并发控制意味着一次可以有多个用户访问一条记录,但只有其中一个用户可以提交对该记录的更改。

  • Table-level auditing表级审计
    Use the Database table-level auditing option to enable table-level auditing.使用数据库表级审计选项启用表级审计。

  • Exit points出口点
    An exit point is a callback function that you write.退出点是您编写的回调函数。 It is executed at a predefined strategic point by the server.它由服务器在预定义的战略点执行。

  • Entity inheritance实体继承
    Input meta-model entity classes can subclass other entity classes.输入元模型实体类可以子类化其他实体类。

  • Last updated field最后更新的字段
    The last updated field is a field that you can add to database tables to contain extra information about the modification time of each record for reporting purposes.最后更新的字段是您可以添加到数据库表中的字段,以包含有关每条记录修改时间的额外信息,以用于报告目的。

Also you can check this link and this link for more information!您也可以查看此链接和此链接以获取更多信息!

I copy from this paper , "Entity based Programming Paradigm", Nimit Singhania.我从这篇论文“基于实体的编程范式”中复制,Nimit Singhania。 University of Pennsylvania:宾夕法尼亚大学:

An entity is an abstract unit that represents a group of nodes or sub-entities.实体是代表一组节点或子实体的抽象单元。 It uses the services provided by its sub-entities and collaboration between these sub-entities to achieve its required goals.它使用其子实体提供的服务以及这些子实体之间的协作来实现其所需的目标。 It has its own identity and appears as a single unit to the external world just as in real life a team or an organization is a whole unit and not just a collection of individuals.它有自己的身份,作为一个单一的单位出现在外部世界中,就像在现实生活中,团队或组织是一个整体,而不仅仅是个人的集合。 A distributed system is essentially a hierarchy of entities where each entity has a specific role and provides specific services [...]分布式系统本质上是实体的层次结构,其中每个实体都有特定的角色并提供特定的服务 [...]

[...]The entity abstraction is very similar to an object in object oriented programming. [...]实体抽象与面向对象编程中的对象非常相似。 The key difference between an object and an entity is that an entity is an active and a live unit while an object is passive.对象和实体之间的主要区别在于,实体是一个主动的、有生命的单元,而对象是被动的。 An entity consists of live subentities interacting with each other to provide a service and can possibly interact with the other entities.实体由相互交互以提供服务的活动子实体组成,并且可能与其他实体进行交互。 Whereas, an object consists of only static fields and properties that can be queried and manipulated by the external world.而对象仅由外部世界可以查询和操作的静态字段和属性组成。 But, many insights from object oriented programming can be carried over to this programming paradigm.但是,面向对象编程的许多见解可以延续到这种编程范式中。 We can have classes and types of entities, where a class might provide specific services and functionality to the rest of the system.我们可以拥有类和实体类型,其中一个类可以为系统的其余部分提供特定的服务和功能。 Also, we could define abstract entities which implement the core structure and some basic protocols for interaction between nodes and these could be extended further to realize the actual entities.此外,我们可以定义实现核心结构的抽象实体和节点之间交互的一些基本协议,这些可以进一步扩展以实现实际实体。 Similarly, we could define interfaces that define a set of services.同样,我们可以定义定义一组服务的接口。 These interfaces could be implemented by multiple entities with different guarantees and based on the requirements, one of them could be chosen by the programmer to provide the required service.这些接口可以由具有不同保证的多个实体实现,并且基于需求,程序员可以选择其中之一来提供所需的服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM