Box Mod Cohesion, Low Coupling, Information Hiding

- Nov 01, 2017-

Software design, divided into architecture design and detailed design (Box Mod design) two stages. Architecture design is the design of the software system should be composed of the number of Box Mods, as well as the static relationship between the Box Mod, dynamic relations, interface relations. Box Mod design is based on the design of these Box Mods interface (function), design the data structure and algorithm within the Box Mod (if any).

So, what kind of Box Mod design is good design?

Good Box Mod design, must follow the following design principles: cohesion, low coupling, information hiding.

Detailed design, as long as the ability to guide the program can be.

Assuming the system has been decomposed into a series of Box Mods, how can we design these Box Mods? The three basic principles of modular design are summarized: information hiding, cohesion and low coupling.


Cohesion is a measure of the degree of correlation between components within a Box Mod. Cohesion Box Mod internal contact closely, like an inseparable whole, such a Box Mod function of a single, the implementation of the Box Mod and maintenance difficulty will be greatly reduced.

Low coupling

Coupling is a measure of the degree of dependency between Box Mods. Low coupling means better independence between Box Mods, and changing a Box Mod does not affect other Box Mods.

Cohesion and coupling are closely related, and Box Mods that are strongly coupled with other Box Mods usually imply weak cohesion, while strongly cohesive Box Mods usually imply weak coupling with other Box Mods.

Information hiding

Information hiding means that the Box Mod only exposes things that must be known to the outside world and hides everything else. In the interface design of the Box Mod design, it fully embodies the principle of information hiding-the interface is the external feature of the Box Mod, which should be exposed, and the data structure, algorithm, implement body and so on are the internal characteristics of the Box Mod, should be hidden. A Box Mod provides only limited interfaces, and interfaces are the only way for Box Mods to interact with the outside world.

If the Box Mod is a C + + class, then the interface of the Box Mod is the public function of the class. If the Box Mod is a COM object, then the interface of the Box Mod is the interface of the COM object. A COM object can have multiple interfaces, and each interface is essentially a collection of functions.

The two principles of information hiding and cohesion and low coupling are in the same lineage. They all embody the independent design idea of the Box Mod. In addition, information hiding, but also contains a profound Chinese culture-Xiu Wai Hui. The Box Mod's interface design pursues the simplicity, the efficiency, the small and the beautiful, this is "the outside", the data structure and the algorithm, these complex design concentrates in the Box Mod inside, is "the Hui Zhong".

These design principles have the connotation of beauty. If you can follow these "beautiful" design principles, you can make good modular design.

Previous:No Information Next:Vape Batteries The Basics That Can Be Recycled