Câu hỏi phỏng vấn Software Architecture
Câu hỏi

What is the difference bet...

Câu trả lời

In software architecture, the concepts of cohesion and coupling are fundamental in assessing the quality of code structure and its maintainability. Here's a detailed explanation of each term and how they differ:

Cohesion

Cohesion refers to the degree to which the elements within a single module or component are related to each other. It measures how well the functionalities within a module work together to achieve a single, well-defined purpose. High cohesion within a module means that the module performs a single task or a group of related tasks, making it easier to understand, maintain, and reuse. The higher the cohesion, the better it is for the software's overall structure because it promotes encapsulation and minimizes interdependencies within the module.

There are several types of cohesion, including:

  • Functional Cohesion: When every part of a module is necessary for the execution of a single function.
  • Sequential Cohesion: When the output from one part of a module serves as input to another part.
  • Communicational Cohesion: When parts of a module operate on the same data.
  • Procedural Cohesion: When parts of a module are grouped because they always follow a certain sequence of execution.
  • Temporal Cohesion: When parts of a module are grouped by the timing of their execution (e.g., initialization functions)[1][2][3][4][5].

Coupling

Coupling, on the other hand, describes the degree of interdependence between different modules or components in a system. It indicates how closely connected different modules are and the extent to which the modules rely on each other. Low coupling is generally preferred because it means that changes in one module are less likely to require changes in another, thereby reducing the risk of introducing bugs and making the system easier to refactor and maintain.

Types of coupling include:

  • Content Coupling: When one module uses the content of another module.
  • Common Coupling: When multiple modules share the same global data.
  • Control Coupling: When one module controls the flow of a...
expert

expert

Gợi ý câu hỏi phỏng vấn

middle

Is it better to return NULL or empty values from functions/methods where the return value is not
present?

middle

How Do you update a live heavy traffic site with minimum or Zero Down Time?

senior

Compare Onion vs Clean vs Hexagonal Architectures

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào