Bird
Raised Fist0
Software Engineeringknowledge~10 mins

Coupling and cohesion in Software Engineering - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Coupling and cohesion
Start: Design Module
↓
Check Cohesion
↓
Good
↓
Check Coupling
↓
Good
↓
Final Design Decision
The flow shows checking cohesion first, aiming for high cohesion, then checking coupling aiming for low coupling, leading to a good module design.
Execution Sample
Software Engineering
Module A: Handles user login
Module B: Processes payments
Module C: Sends notifications

Check cohesion and coupling between modules
This example shows three modules with different responsibilities; we check if each module is focused (high cohesion) and if modules interact minimally (low coupling).
Analysis Table
StepModuleCohesion LevelCoupling LevelActionResult
1Module AHighLowEvaluateGood cohesion and low coupling
2Module BMediumHighEvaluateNeeds improvement in coupling
3Module CLowMediumEvaluateNeeds improvement in cohesion
4Design Decision--Refactor Module B and CImprove coupling and cohesion
5Module B (after)HighLowRe-evaluateGood cohesion and low coupling
6Module C (after)HighLowRe-evaluateGood cohesion and low coupling
7Final--ConfirmModules well designed with high cohesion and low coupling
💡 All modules have high cohesion and low coupling, indicating good design.
State Tracker
ModuleInitial CohesionInitial CouplingAfter Refactor CohesionAfter Refactor Coupling
Module AHighLowHighLow
Module BMediumHighHighLow
Module CLowMediumHighLow
Key Insights - 3 Insights
Why is high cohesion important in a module?
High cohesion means the module focuses on a single task, making it easier to understand and maintain, as shown in execution_table steps 1 and 5.
What problems arise from high coupling between modules?
High coupling means modules depend too much on each other, making changes risky and complex, as seen in step 2 before refactoring.
How does refactoring improve coupling and cohesion?
Refactoring reorganizes code to reduce dependencies and focus module tasks, improving both cohesion and coupling, demonstrated in steps 4 to 6.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 2. What is the coupling level of Module B?
AHigh
BLow
CMedium
DNone
💡 Hint
Check the 'Coupling Level' column in row for step 2.
At which step does Module C achieve high cohesion after refactoring?
AStep 3
BStep 1
CStep 6
DStep 7
💡 Hint
Look at the 'Cohesion Level' for Module C after refactor in step 6.
If Module B had remained with high coupling, what would likely happen to the design?
AModules would be independent
BChanges in Module B could affect others negatively
CDesign would be easier to maintain
DCohesion would automatically improve
💡 Hint
Refer to key_moments about problems caused by high coupling.
Concept Snapshot
Coupling and Cohesion Quick Reference:
- Cohesion: How focused a module is on a single task; aim for high cohesion.
- Coupling: How much modules depend on each other; aim for low coupling.
- High cohesion + low coupling = easier maintenance and better design.
- Refactor to improve cohesion and reduce coupling.
- Check modules individually and their interactions.
Full Transcript
This visual execution trace shows how software modules are evaluated for cohesion and coupling. Cohesion measures how focused a module's tasks are, with high cohesion meaning the module does one thing well. Coupling measures how much modules depend on each other, with low coupling meaning modules are independent. The trace evaluates three modules: Module A has high cohesion and low coupling, Module B has medium cohesion and high coupling, and Module C has low cohesion and medium coupling. After refactoring, Modules B and C improve to high cohesion and low coupling. Key moments clarify why high cohesion and low coupling matter and how refactoring helps. The quiz tests understanding of these concepts using the execution table. The snapshot summarizes the key points for quick review.

Practice

(1/5)
1. What does low coupling in software design mean?
easy
A. Modules have few dependencies on each other
B. Modules perform many unrelated tasks
C. Modules are tightly connected and dependent
D. Modules share all their data freely

Solution

  1. Step 1: Understand coupling concept

    Coupling measures how much modules depend on each other.
  2. Step 2: Interpret low coupling

    Low coupling means modules have few dependencies, making them independent.
  3. Final Answer:

    Modules have few dependencies on each other -> Option A
  4. Quick Check:

    Low coupling = few dependencies [OK]
Hint: Low coupling means less dependency between modules [OK]
Common Mistakes:
  • Confusing low coupling with high dependency
  • Thinking low coupling means modules do many tasks
  • Mixing coupling with cohesion concepts
2. Which of the following best describes high cohesion in a module?
easy
A. The module depends heavily on other modules
B. The module performs many unrelated tasks
C. The module focuses on a single, well-defined task
D. The module shares data with all other modules

Solution

  1. Step 1: Understand cohesion concept

    Cohesion measures how focused a module is on a single task.
  2. Step 2: Interpret high cohesion

    High cohesion means the module focuses on one clear, well-defined task.
  3. Final Answer:

    The module focuses on a single, well-defined task -> Option C
  4. Quick Check:

    High cohesion = single focused task [OK]
Hint: High cohesion means one clear task per module [OK]
Common Mistakes:
  • Thinking high cohesion means many unrelated tasks
  • Confusing cohesion with coupling
  • Assuming high cohesion means high dependency
3. Consider two modules: Module A calls Module B frequently and shares many variables. Module C performs one clear task independently. Which statement is true?
medium
A. Module A has low coupling and high cohesion
B. Module A has high coupling and Module C has high cohesion
C. Module B has high cohesion and low coupling
D. Module C has high coupling and Module A has low cohesion

Solution

  1. Step 1: Analyze Module A and B relationship

    Module A calls Module B frequently and shares many variables, indicating high coupling.
  2. Step 2: Analyze Module C's task focus

    Module C performs one clear task independently, indicating high cohesion.
  3. Final Answer:

    Module A has high coupling and Module C has high cohesion -> Option B
  4. Quick Check:

    High coupling = many dependencies; High cohesion = focused task [OK]
Hint: Frequent calls = high coupling; single task = high cohesion [OK]
Common Mistakes:
  • Mixing which module has high coupling
  • Confusing cohesion with coupling
  • Assuming independence means low cohesion
4. A software module is designed to handle user input, process data, and generate reports all in one. What is the main problem here?
medium
A. The module has low cohesion
B. The module has low coupling
C. The module is highly focused
D. The module is loosely connected

Solution

  1. Step 1: Identify tasks in the module

    The module handles user input, processes data, and generates reports, which are different tasks.
  2. Step 2: Assess cohesion level

    Because it does many unrelated tasks, the module has low cohesion.
  3. Final Answer:

    The module has low cohesion -> Option A
  4. Quick Check:

    Multiple unrelated tasks = low cohesion [OK]
Hint: Many tasks in one module means low cohesion [OK]
Common Mistakes:
  • Confusing low cohesion with low coupling
  • Thinking multiple tasks mean high cohesion
  • Ignoring the definition of cohesion
5. You have a large software system with modules that share many variables and perform multiple unrelated tasks. To improve design, which approach should you take?
hard
A. Increase coupling and decrease cohesion
B. Increase both coupling and cohesion
C. Keep coupling and cohesion as they are
D. Decrease coupling and increase cohesion

Solution

  1. Step 1: Identify current design issues

    Modules share many variables (high coupling) and perform unrelated tasks (low cohesion).
  2. Step 2: Apply good design principles

    Good design aims for low coupling (less dependency) and high cohesion (focused tasks).
  3. Final Answer:

    Decrease coupling and increase cohesion -> Option D
  4. Quick Check:

    Good design = low coupling + high cohesion [OK]
Hint: Aim for less dependency and focused tasks [OK]
Common Mistakes:
  • Thinking increasing coupling improves design
  • Confusing cohesion with coupling
  • Ignoring the benefits of modular design
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard