2IRR00 · Topic 06
Making Software Manageable
Separation of concerns, encapsulation, coupling/cohesion, DRY
Separation of concerns & encapsulation
Separation of concerns divides a system (via divide-and-conquer) into units with minimal overlap; encapsulation places data + its operations into a unit and exposes only a controlled interface.
Divide and conquer: split the problem, solve smaller independent problems, integrate the solutions.
Abstraction: hide and generalise details to reduce complexity (level differs: use-case model vs code).
Encapsulation / modularity / information hiding: put relevant data into a unit and expose it only via a few public methods.
A 'unit' can be a method, class, or package depending on the abstraction level.
Common mistakes
- Monolithic methods with multiple responsibilities depending on global variables — changing one variable impacts everything; reuse is impossible.
Exam tips
- Encapsulation ideas (MCQ): putting all-but-only relevant data into one unit ✔; providing access via an interface ✔. NOT 'not repeating code' (that's DRY) and NOT 'writing a god class'.
Separation of concerns & encapsulation practice
1 questions
Coupling, cohesion & information hiding
Coupling is the degree of interaction between units; cohesion is the degree to which a unit fulfils one purpose. Design goal: minimise coupling, maximise cohesion.
Information hiding: reveal as little as needed; prevent data manipulation; ensure unit integrity; expose a single controlled interface — done via visibility (public/package/protected/private) and interfaces.
The interface to a class is its public methods.
DRY (Don't Repeat Yourself): solve each problem in one place; avoid copy-paste clones; unify similar code via parameters/auxiliary methods.
Good separation: one unit = one well-defined problem; small interfaces (few parameters, pass only needed data, combine into reference types); small/clear methods.
Common mistakes
- High coupling via many parameters/method calls between classes; low cohesion (a class doing unrelated things).
- Copy-paste-edit reuse (creates clones).
Exam tips
- Definitions: Coupling = degree of interaction BETWEEN units; Cohesion = degree to which a unit fulfils a SINGLE purpose.
- Principle slogan: Minimise Coupling, Maximise Cohesion. DRY = Don't Repeat Yourself.
Coupling, cohesion & information hiding practice
1 questions