Home >Backend Development >Golang >Coupling and Cohesion

Coupling and Cohesion

DDD
DDDOriginal
2024-11-24 14:06:36780browse

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

Acoplamento e Coesão

Acoplamento e Coesão

Acoplamento e Coesão

Acoplamento e Coesão

Acoplamento e Coesão

The above is the detailed content of Coupling and Cohesion. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn