Anatomy object frame (1)-entity and operation class

Source: Internet
Author: User

1. What is an entity?

In the target business field where we construct a system, some objects are mainly managed or processed by the outside world. These objects are mainly processed or processed, this type of object is called an object, and this type of object is based on data. Generally, it only has attributes (or fields ), does not include or only contains a small number of endogenous methods (mainly some self-processing methods, these methods do not operate other objects, do not produce dependencies on other external objects, such as cloning, format ). To put it bluntly, an object is a data object. struct and classes can be used to describe it. The entity class can be nested, that is, the attributes of the object class can also be another entity type (or itself ). Operations (Business and data processing) correspond to entity classes ).

2. entity Operations

Here, the operation class mainly refers to the class that the pointer operates on the object. These operation classes do not include any data attributes except the attributes necessary to guide the operation method. The methods contained in the operation class are generally for objects or object sets. Generally, classes that operate on a single object and a set of operating entities are separated. Operations on a single object, such as format display, reflection value assignment, and reflection value. For an object set, add, modify, read, delete, query, filter, and count objects, statistics and other operations. The difference between the entity operation class and the business processing class is that the entity operation class only targets the entity class itself, without the business logic color. From the database perspective, the entity operation class is equivalent to the Database SQL.

3. Why should entities be separated from operations?

Entities represent data, and operations represent data processing methods. This separation of entity and entity Operations is the next Wise change in Object-Oriented Programming. On the one hand, object orientation is only a perspective of analysis and design, it does not represent the whole of the world. The traditional mode of separating data from methods (process-oriented) still has its advantages, especially in the aspect of large-scale data processing. Second, the operation methods of the object class and object, especially the methods applied to the object by the outside, are also difficult to understand logically. I have always felt that process-oriented and object-oriented are not opposite. They are both opposed and unified. Object-oriented focuses on the whole and the whole, while process-oriented focuses on local and implementation.

Benefits of separation of entity classes and operations:

1) convenient storage, transportation, sharing and exchange

In general, entities are very simple, because there is no method, but only data, so it is easy to store, transport, share and interact. It facilitates processing in XML format.

2) Easy to reuse operations

If an object follows certain rules (metadata is often used to describe it), many operations on the object can be used in a common way. For example, adding, deleting, modifying, and querying objects.

3) Ease of integration with file and Database Systems

We know that file systems and database systems mainly store data, and the processing of such data is externally attached. With the separation of entities and operations, entities are very suitable for file data and database data with structure words.

Converts the data to facilitate processing in the memory.

4) data is represented by entities rather than simply records. The characteristics of classes can be well utilized to aggregate data and these objects can be better treated as a whole, such as order entities, you can consider the single table header and order details as a whole.

Bad:

1) because an object only contains attributes and does not provide or only provides a small number of methods, the methods that can be encapsulated in an object must also be provided externally, and the entity must fully expose itself. From this perspective, the object encapsulation is damaged from the object-oriented perspective. At the same time, because the entity mainly contains static features and polymorphism, inheritance does not play a major role (it provides certain interface attributes for implementation ). In fact, this is not a bad thing. Some things do not need to enter the "clean" state.

 

Here, we may find that the separation of entities and operation classes is a bit of a database taste. In fact, some persistence layer frameworks are a simplified memory relational database in a sense, typical examples are linqtosql and adonetentity framework.

 

........

Next, we will focus on the main functions and general architecture of the physical framework. For some key technologies, we will provideCode.

You are also welcomed to make corrections.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.