7 ± 2

zhaozj2021-02-16  56

Psychology research believes that people can only handle 7 ± 2 things, which means that people can only process 5 to 9 things at the same time. If this range is exceeded, it is prone to chaos or errors. It is said that in some ancient civilization, "seven" has a lot of meaning.

7 ± 2 principle shows the limitations of human cognitive ability. In order to overcome this limitations, our ancestors have treated the method of dividing and conn que. When studying a complex thing, it is divided into a number of small parts and gradually refined until you can grasp. Then, in turn, study the links between parts, and finally reach the purpose of understanding the whole thing.

Taking the human body as an example, the human body can be seen as a four-layer structure: system, organ, organization, and cells. The human body is composed of several systems, such as respiratory systems, digestive systems, circulatory systems, nervous systems, etc., system, composed of several organs, and organs consist of several tissues, and tissue consists of cells. This way we are studying every part, and there is not too much question. This is easy to describe and it is also easy to understand. If you do not join the system at the time of dividing, the human body is seen as a heart, the brain, spleen, liver, stomach, intestines, lungs, hands, feet, legs, arms, eyes, ear, nose, throat, etc. It is beneficial to understand the relationship between the organs and the operation of the human body. In essence, the human body is composed of cells, but how much help us understand the human body? Therefore, reasonable layering is a powerful weapon we describe problems and understanding problems.

The human body is a complex system, but we can describe quite clearly in a four-layer structure. Ingenious, there are quite a few software systems to describe four-layer structure. To divide each part into seven small parts, a four-layer structure can describe 2800 (7 7 * 7 7 * 7 * 7 7 * 7 * 7 * 7) subsystem or class. How many software systems exceed this range?

An important task of software design is to block, hierarchical, make each piece, each layer, and complete a function, but it is more complicated. And the coupling between each block and each layer is as small as possible. Such software systems are both easy to develop and easy to maintain. Unfortunately, a software may have a lot of division. How to make the division more reasonable, then you have to see the experience and feel. However, if a division violates 7 ± 2 principle, it is likely that this division is unreasonable. The big principle is: not to complete the sub-portion of the same function, do not put it together, not the sub-part of the same abstraction, do not place the same layer. It is obviously inconsistent with the heart to the respiratory system, and it is not appropriate to bring the organs of epithelial tissue and digestive systems. Of course, don't expect to be able to divide it once, adjust it at any time.

In software development, you should consciously use 7 ± 2 principle,

l Each UML map does not exceed 7 ± 2 entities as much as possible.

l The public function of each interface or an abstract class is not more than 7 ± 2.

l Don't be too long for each function. During the function, the tightly related expression does not leave a blank line, forming an expression group, separated from other expression groups. Each expression group is preferably comment, explaining the behavior of the entire expression group. There are not too many rows of each expression group.

l The physical structure of the software is to match the logical structure. In this way, if the logical structure complies with 7 ± 2 principle, the physical structure can automatically meet the requirements.

l The number of people in each development team is better under seven people.

l, etc.

Whether we like or not, 7 ± 2 principles are limited to human beings. Maybe this principle is a beautiful manifestation, isn't it simple to say? Then let every module, every class, every function is beautiful.

转载请注明原文地址:https://www.9cbs.com/read-23969.html

New Post(0)