官术网_书友最值得收藏!

Entities

Entities are certain types of objects that are identifiable and remain the same throughout the different states of products/services. These objects are not identified by their attributes, but by their identity and thread of continuity. These types of objects are known as entities.

This sounds pretty simple, but it carries complexity. You need to understand how we can define entities. Let's take an example of a table-booking system, where we have a restaurant class with attributes such as restaurant name, address, phone number, establishment data, and so on. We can take two instances of the restaurant class that are not identifiable using the restaurant name, as there could be other restaurants with the same name. Similarly, if we go by any other single attribute, we will not find any attributes that can singularly identify a unique restaurant. If two restaurants have all the same attribute values, they are therefore the same and are interchangeable with each other. Still, they are not the same entities, as both have different references (memory addresses).

Conversely, let's take a class of US citizens. Each citizen has his or her own social security number. This number is not only unique, but remains unchanged throughout the life of the citizen and assures continuity. This citizen object would exist in the memory, would be serialized, and would be removed from the memory and stored in the database. It would even exist after the person is deceased. It would be kept in the system for as long as the system exists. A citizen's social security number remains the same irrespective of its representation.

Therefore, creating entities in a product means creating an identity. So, give an identity to any restaurant in the previous example, then either use a combination of attributes, such as restaurant name, establishment date, and street, or add an identifier such as restaurant_id to identify it. The basic rule is that two identifiers cannot be the same. Therefore, when we introduce an identifier for an entity, we need to be sure of it.

There are different ways to create a unique identity for objects, described as follows:

  • Using the primary key in a table.
  • Using an automated generated ID (generated by a domain module). A domain program generates the identifier and assigns it to objects that are being persisted between different layers.
  • A few real-life objects carry user-defined identifiers themselves. For example, each country has its own country code for dialing ISD calls.
  • Using a composite key. This is a combination of attributes that can also be used to create an identifier, as explained for the preceding restaurant object.
Entities are very important for domain models. Therefore, they should be defined from the initial stage of the modeling process.

When an object can be identified by its identifier and not by its attributes, a class representing these objects should have a simple definition, and care should be taken with the life cycle continuity and identity. It's imperative to identify objects in this class that have the same attribute values. A defined system should return a unique result for each object if queried. Designers should ensure that the model defines what it means to be the same thing.

We can summarize entities in the following five points (example, customer, restaurant are entities in OTRS application):
  • Certain types of objects that are identifiable
  • They remain the same throughout the different states of the product/service
  • Not identified by their attributes, but by their identity and thread of continuity
  • Ways to create entities—primary key, automated generated identity, user-defined identities, or a composite key
  • They should be defined at the initial stage of the modeling process
主站蜘蛛池模板: 连州市| 临湘市| 泽州县| 龙里县| 阿城市| 睢宁县| 天全县| 新密市| 玛多县| 旺苍县| 东海县| 无极县| 临西县| 阿图什市| 旌德县| 孝义市| 甘德县| 德庆县| 巴楚县| 咸丰县| 阿鲁科尔沁旗| 广德县| 宝兴县| 蓬莱市| 胶州市| 庄河市| 宁乡县| 息烽县| 盘锦市| 分宜县| 赤峰市| 永平县| 清河县| 昌图县| 伊川县| 上思县| 巩义市| 大城县| 策勒县| 东至县| 延长县|