What is an object class! Answer questions from Golden ocean

Source: Internet
Author: User

In fact, I don't want to comment on this question any more, but I have a lot to answer, so I have to post a reply. I have explained the hierarchy from many aspects before, but this guy in the Entity class is a really different type of hacker, which leads to questions from Jin, as it involves another post, I have to make a few notes.

First, what is an entity class?

Here I make a definition that conforms to most systems: the entity class only has attributes and the attributes correspond to the column definitions of the database table one by one. It is used as a carrier to transmit data between different layers. That is, DTO (Data transfor object, which is roughly spelled this way) data transmission object, which is called pojo in Java. So I think the definition of this class is a data structure.

Let's look back at the data structure.ProgramIs the data structure +AlgorithmThis sentence is classic. In an object-oriented program, classes are a collection of data structures and algorithms. The only difference is that object-oriented packaging and data structures are private, in this way, the coupling between classes is reduced by using methods as contracts. However, this cannot fundamentally solve the problem. The data of the program does not come out of thin air. Both input and output must have an interface with the outside. At this time, this interface is a coupling point. When talking about coupling, it is estimated that Jin did not take it seriously. In the interface contract, we should consider using tag coupling.

------------ Shameless self-reference ----------------

Tag Coupling: A group of modules pass the record information through the parameter table, that is, tag coupling. This record is a sub-structure of a data structure, rather than a simple variable.

------------------------------------------

In fact, the entity class is the sub-structure of a certain data structure.

We can think that the database structure is also a data structure (in the broad definition of the data structure, it is indeed a data structure and a data storage structure ), the ing of the object class as the database table structure in the program is also a data structure. So

Createuser (userentity user)

This "Interface Definition" (note that this interface is not an interface of another type) is called Tag coupling.

 

Then compare the definition of public coupling:

------------ Shameless self-reference ----------------

Public Coupling: If a group of modules access the same public data environment, the coupling between them is called public coupling. A public data environment can be a global data structure, a shared communication area, and a public coverage area of the memory.

------------------------------------------

The database, as a global data structure, is naturally public-coupled. If such a definition is necessary, it cannot be solved. This is an unsolved problem, to use a database, for example, coupling with this public data structure.

 

Note that,Coupling is the way of message transmission and data transmission between modules. coupling is neutral and unavoidable.

 

So in this regard, the effort is purely useless. That is, even if the entity class is not used, the database structure changes, that is, the data structure changes, so the modificationCodeIs an inevitable and unchangeable structure. Just as the algorithm that uses the same operation array for Bubble Sorting can work normally if the array is replaced with hashtable?

 

Dataset, regardless of the strong or weak type, datareader must be coupled with the database, so there is no difference between the two and the entity class.

 

Don't we do anything?The answer is no.

 

In my opinion, the solution isDynamic. Orm uses the definition of an object as a contract to dynamically access data. Therefore, if the database changes, we only need to modify the object class and definition, which greatly reduces the modification to the program. Spring dynamic the dependency on the business module, and we can easily replace the business module. If the database changes, we only need to replace the business modules involved in the table modified by the database with the new ones based on modifying the object classes and definitions. On the interface, dynamic forms and Data Controls can greatly reduce the modification scope.

 

 

Here, we need to explain to Jin: Even if your controls use events to strip the work of some business logic, the business logic is coupled with data, so what do you use to let the business logic know your data structure? Array? Datareader? Dataset?

The data structure that the form depends on changes, and the configuration changes unchanged? The so-called configuration is a continuation of the program. I think the configuration is actually an external DSL (see why XML sucks)

Modifying the configuration file and modifying the program often lead to a misunderstanding that it is better to modify the XML file than to modify the program. But we do not know that the modification of the XML file has not been detected during compilation, the program is tested during compilation, and the error rate of modifying XML is 100 times higher than that of modifying the program (I seem to have missed why XML sucks ).

Speaking of this, the structure of the data table has changed. In fact, modification to the interface will still be involved, but your control will strip the modification from the page file, changed to the configuration file (or configuration data ). If there is no tool to complete the configuration, the error rate is much higher than the modification page, and debug is much more complex.

 

 

Some people who want to reply to questions from Kim also said: many students have great deviations in understanding spring. Spring is a collection of IOC containers, AOP containers, and abstract services. Of course, we use the first two most. Many of you are confused about IOC and AOP. IOC is the concept of dependency injection, which is actually the implementation of the Virtual Factory mode and proxy mode, while AOP is a method slice, that is to say, another code to be executed is embedded dynamically before and after the call method (actually, the method ).

 

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.