Coupling Concepts
- Coupling: Indicates the extent to which a module knows and depends on others.
- Low Coupling: Changes in one module have less impact on the others.
- High Coupling: Changes in one module can affect several others.
Cohesion Concepts
- Cohesion: Indicates how well the responsibilities of a module are grouped.
- High Cohesion: The module has related responsibilities and is focused on carrying out a single task.
- Low Cohesion: Responsibilities are less related.
Communication approaches
- Messaging communication.
- Traditional Communication.
Messaging communication
- Asynchronous communication.
- Modules send and receive messages.
- Definition of message contracts via interfaces.
- Promotes decoupling between modules.
- Modules communicate via Message Bus
- Tools: RabbitMQ, Kafka, etc.
Traditional Communication
- Call functions between modules.
- Use of objects, structs, traits, between packages.
- One module calls another module.
- Use of namespaces, packages, modules.
Observations
- It is difficult to guarantee total decoupling
- There is always some dependency between modules.
- Even with the use of contracts, interfaces and messaging, there will be a level of dependency.
- It is normal for there to be dependencies between one module and another.
Source Code:
- https://github.com/ortizdavid/golang-modular-software
![Acoplamento e Coesão](https://img.php.cn/upload/article/000/000/000/173242839922150.jpg)
![Acoplamento e Coesão](https://img.php.cn/upload/article/000/000/000/173242840185631.jpg)
![Acoplamento e Coesão](https://img.php.cn/upload/article/000/000/000/173242840466980.jpg)
![Acoplamento e Coesão](https://img.php.cn/upload/article/000/000/000/173242840679973.jpg)
![Acoplamento e Coesão](https://img.php.cn/upload/article/000/000/000/173242840764027.jpg)
![Acoplamento e Coesão](https://img.php.cn/upload/article/000/000/000/173242841735375.jpg)
The above is the detailed content of Coupling and Cohesion. For more information, please follow other related articles on the PHP Chinese website!