当前位置:网站首页>Software engineering - high cohesion and low coupling
Software engineering - high cohesion and low coupling
2022-06-26 08:04:00 【Live Firestone】
Interface design principles
Good interface should meet the six principles of design pattern , A lot of design patterns , The framework is based on the starting point of high cohesion and low coupling .
- Principle of single responsibility : A class is only responsible for the corresponding responsibilities in a functional area .
- Opening and closing principle : A software entity should be open to extension , Turn off for changes .
- Richter substitution principle : All reference base classes ( Parent class ) Must be able to transparently use objects of its subclasses .
- Dependence Inversion Principle : Abstractions should not depend on details , Details should depend on abstraction . In other words , To program for an interface , Instead of programming for implementation .
- Interface isolation principle : Using multiple specialized interfaces , Instead of using a single master interface , That is, the client should not rely on interfaces it does not need
- Dimitar's law : A software entity should interact with as few other entities as possible , For example, appearance mode , Unified interface for external exposure
High cohesion and low coupling
- cohesion : Each module can complete its own functions as independently as possible , It doesn't depend on the code outside the module
- coupling : The complexity of the interface between modules , The more complex the connection between modules, the higher the coupling , Pull one hair and move the whole body .
- Purpose : Make the module " Reusability "," portability " Greatly increase .
- High cohesion : A software module is composed of highly relevant code , Only one task , That is to say, the principle of single responsibility . The cohesion of the module reflects the tightness of the module . A module only needs to do one thing well , Don't be overly concerned about other tasks . The advantage of high cohesion is that it can improve the reliability of the program
- Low coupling : Between modules , System to system interaction , Is inevitable , However, we should try to reduce the situation that a single module cannot be used independently or transplanted due to interaction , Provide as many separate interfaces as possible for external operation , This is what we call " Low coupling ".
Generally, the more cohesive the modules in the program structure are , The lower the coupling between modules .
Coupling and cohesion are two qualitative criteria of module independence , When dividing the software system into modules , Strive for high cohesion and low coupling , Improve the independence of modules , Lay the foundation for designing high quality software structure
The type of coupling ( Coupling strength from low to high )
No direct coupling : There is no direct relationship between the two modules , The connection between them is completely realized through the control and call of the main module . The coupling is the weakest , Module independence is the strongest . Sub modules do not need to know the existence of each other , Connections between sub modules , All become the connection between the sub module and the main module
Data coupling : When one module accesses another , Between each other is through simple data parameters ( It's not a control parameter 、 Common data structures or external variables ) To exchange input 、 transport Informative
Tag coupling : It refers to the data structure passed between two modules , For example, array names in high-level languages 、 Record name 、 File names and so on are marked , In fact, it is the address of the data structure .
Control coupling : When one module calls another , What is passed is the control variable ( Like a switch , Signs, etc ), The tuned module selectively performs a function within the block through the value of the control variable
External coupling : A set of modules all access the same global simple variable , And the information of the global variable is not passed through parameters , It's called external coupling
Public coupling : Refers to the coupling between modules that interact through a common data environment . Complex programs with common coupling increase with the number of coupling modules .
a. Unable to control the access of each module to public data , It seriously affects the reliability and adaptability of software modules .
b. Make the maintainability of software worse . If a module modifies public data , It will affect the relevant modules
c. Reduces the intelligibility of the software . It's not easy to know which data is used by which Shared by modules , It's difficult to make mistakes
Content coupling : This is the highest level of coupling , And the worst coupling .
a. One module directly accesses the internal data of another module ;
b. One module is not transferred to the inside of another module through the normal entrance ;
c. Part of the program code of the two modules overlaps
d. A module has multiple entrances .
Content coupling can occur in assembly languages . Most high-level languages have been designed not to allow content coupling . This kind of coupling has the strongest coupling , Module independence is the weakest .
Cohesion classification ( low –> high )
- To gather by chance : It means that there is no relationship between the processing elements in a module .
- Logical cohesion : It refers to the execution of several logically similar functions in the module , Through the parameters to determine which function the module completes .
- Time converges : The module formed by combining the actions that need to be executed at the same time is called time cohesion module .
- Communication cohesion : All processing elements in the module operate on the same data structure ( It is also called information cohesion ), Or all elements in the module use the same input data or produce the same output data .
- Order cohesion : It refers to that each processing element in a module is closely related to the same function and must be executed in sequence , The output of the former function element is the input of the next function element
- Functional cohesion : This is the strongest cohesion , It means that all elements in the module complete a function together , Be short of one cannot . Coupling with other modules is the weakest .
It is generally believed , To gather by chance 、 Logical cohesion and temporal cohesion belong to low cohesion , Communication cohesion belongs to medium cohesion , Sequential cohesion and functional cohesion belong to high cohesion . Try to be as cohesive as possible when designing software , And can identify low cohesion modules , Thus, the cohesion of the module can be improved by modifying the design , Reduce coupling between modules , Improve the independence of modules , Lay the foundation for designing high quality software structure .
边栏推荐
- Uploading pictures with FileReader object
- Redis (5) -- Talking about compressed list
- Is it safe for individuals to buy stocks with compass software? How to buy stocks
- Area of Blue Bridge Cup 2 circle
- [UVM practice] Chapter 3: UVM Fundamentals (3) field automation mechanism
- Comparison version number [leetcode]
- How to debug plug-ins using vs Code
- How to define a digital factory and what is the relationship with smart factory and industry 4.0
- Project management learning
- 我想要股票账户优惠开户,如何操作?手机开户安全么?
猜你喜欢

Two models of OSPF planning: double tower Raider and dog tooth crisscross

Webrtc has become the official standard of W3C and IETF, and mobile terminal development

Gavin teacher's insight on transformer live class - multi state transition of financial BOT and rasa interactive behavior analysis of Rasa project (52)

What is Wi Fi 6 (802.11ax)? Why is Wi Fi 6 important?

Interview for postgraduate entrance examination of Baoyan University - machine learning

Database learning notes II

Yyds dry inventory kubernetes easy service discovery and load balancing (11)

Wechat applet beginner level chapter

PCB miscellaneous mail

Ping An technology's practice of migrating from Oracle to ubisql
随机推荐
2022 ranking of bank financial products
JS precompile - Variable - scope - closure
What if the service in Nacos cannot be deleted?
Which securities company has the lowest Commission for opening a mobile account? Is it safe to open an account online?
PyTorch-12 GAN、WGAN
Chapter VII (structure)
What is the difference between bone conduction earphones and ordinary earphones? Advantages of bone conduction earphones
信息学奥赛一本通 1355:字符串匹配问题(strs)
JMeter performance testing - Basic Concepts
[UVM practice] Chapter 2: a simple UVM verification platform (5) build test cases
Take you three minutes to get started typescript
Chapter 3 (data types and expressions)
ASP. Net and Net framework and C #
Data governance: from top project to data culture!
我想造SQL数据(存储结构)
Understanding of closures
Real machine debugging of uniapp custom base
Area of Blue Bridge Cup 2 circle
Uniapp wechat withdrawal (packaged as app)
The first multi platform webcast of 2021ccf award ceremony pays tribute to the winners! CCF outstanding engineer