What's the difference between entity and class?

怎甘沉沦 提交于 2019-11-28 16:27:32

问题


Is entity an instance of class?


回答1:


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.




回答2:


To add one more point

Class is a syntactic i.e. 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 i.e. relating to meaning in language or logic. An entity is something that exists in itself, actually or potentially, concretely or abstractly, physically or not. It needs not be of material existence.

Object is a in-memory value referenced by identifier, it is an instance of a Class.




回答3:


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.




回答4:


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.




回答5:


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.

So we could say, that entity, object and class instance are interchangeable.




回答6:


I copy from this paper, "Entity based Programming Paradigm", 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.




回答7:


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.

  • 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!



来源:https://stackoverflow.com/questions/2550197/whats-the-difference-between-entity-and-class

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!