Design Knowledge Area in SWEBOK
ุงูู Design = ุชุญููู ุงูู requirements ูู system structure ู ูุธู ููุนูุงู ูุญูู ุงูู FR ูุงูู NFR.
๐๏ธ Fundamentals
Modularity, abstraction, separation of concerns.
๐ Design Process
High-level (architecture) + Low-level (components).
๐ Principles
Patterns, modular design, maintainability, scalability.
๐ Models
UML, ER diagrams, class & sequence diagrams.
โ Evaluation
Reviews, prototyping, metrics.
๐๏ธ Architecture
System structure + NFR (perf, security).
- Higher-level design (Architecture)
- Module-level design (Classes, interactions)
- Algorithms
- Database
- User Interface
What is Modularity?
ููุนุฉ ู ู ุงูุฑู ู vs ููุนุฉ LEGO. ุงูุฃููู ูู ุฎุฑุจุช ูููุง ูุชุฑูุญ. ุงูู LEGO ุชูุฏุฑ ุชุณุชุจุฏู ูุทุนุฉ ูุชุนูุฏ ุชุดุบูู ุงูุจุงูู.
- ุงูู Software ุงูู ู modular: ุงูุฃุฌุฒุงุก ู ู ูู ุชุชุจุฏู ุฃู ุชุชุนุงุฏ ุงุณุชุฎุฏุงู ูุง ูู software ุชุงูู.
- ุงูู Modularity ุจุชุฎูู ุงูู software ุฃุณูู ูู ุงูููู ูุฃู ูู ุฌุฒุก ุตุบูุฑ ูุชุฏุฑุณ ููุญุฏู.
ุฃูุชุฑ ู ู ุชุนุฑููุ ูููู ุจููุตููุง ูููุณ ุงูููุฑุฉ:
- "A program unit that is discrete and identifiable with respect to compiling, combining, and loading."
- "A logically separable part of a program."
- "A set of source code files under version control that can be manipulated as one."
- "A collection of both data and the routines that act on it." (object-oriented view)
Module Complexity
3 ู ูุงููุณ ูุฌูุฏุฉ ุงูู module: Cyclomatic Complexity, Cohesion, Coupling.
ุงูุฏุฑุฌุฉ ุงููู ุจููุง design ุฃู code ุตุนุจ ุงูููู ุจุณุจุจ:
- ูุชุฑ ุงูู components
- ูุชุฑ ุงูู relationships ุจูููู
ุฃู ุงูุฏุฑุฌุฉ ุงููู ุจููุง implementation ุตุนุจ ุงูู understand and verify.
ุงูุนูุณ: ุงูุฏุฑุฌุฉ ุงููู ุจููุง design ุฃู code straightforward ูุณูู ุงูููู .
ูุฏููุง: ุชุตู ูู modules ุจุณูุทุฉ.
- McCabe Cyclomatic Complexity โ ุชุนููุฏ function ูุงุญุฏุฉ.
- Coupling โ ุงุนุชู ุงุฏ ุงูู modules ุนูู ุจุนุถูุง.
- Cohesion โ ุชู ุงุณู ุงูู module ู ู ุฌููู.
Cyclomatic Complexity โ McCabe 1974 โญ
ุนุฏุฏ ุงูู ุณุงุฑุงุช ุงูู ุณุชููุฉ ูู piece ู ู ุงูููุฏ. ูู ู ุง ุฒุงุฏุ ูู ู ุง ุงูููุฏ ุฃุตุนุจ ูุฃูุชุฑ ุนุฑุถุฉ ููู bugs.
1. Decisions + 1
ุนุฏุฏ ุงูู binary decisions (if, while, case) + 1.
2. Closed Areas + 1
ุนูู ุงูู Control Flow Graph: ุนุฏุฏ ุงูู ูุงุทู ุงูู ุบููุฉ (enclosed regions) + 1.
3. Edges โ Nodes + 2P
V(G) = E โ N + 2P
P = ุนุฏุฏ ุงูู separate sub-graphs (ุนุงุฏุฉ = 1).
switch ุจู 3 casesุ ุงุนุชุจุฑู ู
ุซู 2 simple decisions (ุชุชูุฑุน ุดุฌุฑุฉ binary).ุนูู Control Flow Graph ู ุนูู:
std::string categorize(int value) {
if (value > 100) { // decision 1
return "Very High";
} else if (value > 75) { // decision 2
return "High";
} else if (value > 50) { // decision 3
return "Medium High";
} else if (value > 25) { // decision 4
return "Medium Low";
} else if (value > 0) { // decision 5
return "Low";
} else {
return "Negative";
}
}
// V(G) = 5 decisions + 1 = 6
| V(G) | ุงูุชูููู | ุงูุชูุตูุฉ |
|---|---|---|
| 1โ10 | Manageable | ุณูู ุงูููู ูุงูุงุฎุชุจุงุฑ. ุงูุฃูุฏุงู ุงูู ุซูู. |
| 11โ20 | Moderate | ู ุญุชุงุฌ testing ุฃูุชุฑุ review ุนูุงูุฉ. ู ู ูู refactoring. |
| 21โ50 | High Complexity | ุตุนุจ ุงูููู /ุงูุตูุงูุฉ. ุบุงูุจุงู candidate ููู refactor. |
| > 50 | Very Complex | ๐จ Red flag โ ูุงุฒู refactoring. |
1. ุญุงูุธ ุนูู V(G) < 10 ุฎุตูุตุงู ููููุฏ ุงูุญุฑุฌ.
2. ุงุณุชุฎุฏู complexity ูู guideline ููู refactoring.
3. ุจุนุถ ุงูู algorithms (statemachine, business rules) ูููุง complexity ุนุงููุฉ ุจุทุจูุนุชูุง.
ุนุฏุฏ test cases ุงูู ุทููุจุฉ ูู full path coverage = V(G).
ูู V(G) = 4ุ ู ุญุชุงุฌ 4 test cases ูุชุบุทูุฉ ูู ุงูู ุณุงุฑุงุช ุงูู ุณุชููุฉ.
ุนุฏุฏ test cases ููู statement coverage ู ู ูู ูููู ุฃูู ุจูุชูุฑ โ ุฃุญูุงูุงู test case ูุงุญุฏ ุจูู ุฑ ุจูู ุงูู statements (ูู ุงูููุฏ sequential).
Cohesion โ ุชู ุงุณู ุงูู Module โญ
ู ุฏู ุงุฑุชุจุงุท ุงูู functions ุฏุงุฎู module ูุงุญุฏ ุจุจุนุถูุง. High cohesion = ุฌูุฏ. 7 ู ุณุชููุงุช ู ู ุงูุฃุณูุฃ (Coincidental) ููุฃูุถู (Functional).
Cohesion = ุฏุฑุฌุฉ ุงุฑุชุจุงุท ุงูู elements ุฏุงุฎู module ูุงุญุฏ ุจุจุนุถ. ูู ุงูู functions ูููุง ุจุชุนู ู ุญุงุฌุฉ ูุงุญุฏุฉ related โ High cohesion.
ุงููุฏู: High cohesion + Low coupling.
StringUtils ููู toUpper, toLower, trim โ ูููุง string operations.parseInput() โ validate() โ process().open file โ read โ close.initializeApp() ุงููู ุจูุนู
ู load ููู configs, connect ููู DB, start ููู logger ูููุง ูู ุงูู startup.handleInput(type) ุงููู ุจูุนู
ู switch ุนูู type ูุงูู handlers ู
ุฎุชููุฉ ุฌุฏุงู.parseDate() ู sendEmail() ู encryptPassword().StringUtils ูููุง static functions ูููุง ุจุชุนุงูุฌ Strings โ ุงูุฌูุงุจ: Functional cohesion (ุงูุฃูุถู).ู ู ุงูุฃูุถู ููุฃุณูุฃ:
Functional > Sequential > Communicational >
Procedural > Temporal > Logical > Coincidental
ุฃู: Fancy Sandwich Cooks Prefer Tasty Lemon Cake ๐ฐ
Coupling โ ุงุนุชู ุงุฏ ุงูู Modules ุนูู ุจุนุถูุง โญ
ู ุฏู ุงุนุชู ุงุฏ module ุนูู module ุชุงูู. Low coupling = ุฌูุฏ. ุงูุฏูุชูุฑ ุจูุฐูุฑ 5 ุฃููุงุน: Common Environment ยท Content ยท Control ยท Data ยท Pathological.
Coupling = ุฏุฑุฌุฉ ุงูุงุนุชู ุงุฏ ุจูู modules ู ุฎุชููุฉ. ูู module ุจูุนุฑู ุชูุงุตูู ุฏุงุฎููุฉ ูู module ุชุงูู โ High coupling (ู ุด ุฌูุฏ).
ุงูู goal: ูู module ู ุณุชูู ุจูุฏุฑ ุงูุฅู ูุงู โ ูู ุบูุฑุช module ูุงุญุฏุ ุงูุจุงูู ู ุง ูุชุฃุซุฑุด.
| ุงูููุน | ุงูุชุตููู | ุงููุตู |
|---|---|---|
| ๐ Content | High โ Worst | Module ุจูู access/modify ู ุจุงุดุฑุฉู ููู internals ุจุชุงุน module ุชุงูู. ุฃุนูู ุฏุฑุฌุฉ coupling. ุจููุณุฑ ุงูู encapsulation. fragile ุฌุฏุงู. |
| Pathological | High | Module ุจูุนุชู ุฏ ุนูู ุงูู internal implementation ุจุชุงุน module ุชุงูู / ู ุชุดุงุจููู ุจุดุฏุฉ. ุณููู unpredictable. ู ุคุดุฑ ุนูู ุชุตู ูู ุณูุฆ. |
| Common Environment | Medium | ุงูู Modules ุจุชุดุชุฑู ูู global data / environment. ุฃู ุชุนุฏูู ูู ุงูู global ุจูุฃุซุฑ ุนูู ุงููู. ุจููููู ุงูู encapsulation. |
| Control | Medium | Module ุจูุชุญูู ูู module ุชุงูู ุนู ุทุฑูู flags / control variables. ู ุฑููุฉ ูู ุงูุชูููุฐ ุจุณ ุจุชูููู ุงูู clarity. |
| ๐ Data | Low โ Best | ุงูู Modules ุจุชุชูุงุตู ุนู ุทุฑูู parameters ุจุณ. ู ููุด shared internal state. ุงูููุน ุงูู ุฑุบูุจ. |
let counter = 0; // โ ๏ธ Global shared state
class ModuleA {
increment() { counter++; } // writes global
}
class ModuleB {
display() {
console.log("Count: " + counter); // reads global
}
}
counter global. ูู ModuleC ุถููุชู ุจุชู
ุณุญ ุงูู counterุ ModuleA ู ModuleB ูููู
ููุชุฃุซุฑูุง.โ ุงูุญู: Data Coupling
class Counter {
constructor() { this.value = 0; }
increment() { this.value++; }
get() { return this.value; }
}
function display(count) { // only receives what it needs
console.log("Count: " + count);
}
module ุฎุงุฑุฌู ุจูุชุญูู ูู ุงูู internal state ุจุชุงุน module ุชุงููุ ูุงูุณููู ุจูุนุชู ุฏ ุนูู ุงูู state ุฏู โ unpredictable.
class ModuleA {
int state = 0;
public:
void setState(int s) { state = s; }
void execute() {
if (state == 1) { /* action 1 */ }
else if (state == 2) { /* action 2 */ }
else { /* default */ }
}
};
class ModuleB {
public:
void changeModuleAState(ModuleA& a, int n) {
a.setState(n); // โ ๏ธ B ูุชุญูู
ูู state ุจุชุงุน A ู
ู ุจุฑู
}
};
// main: B ุจูุบููุฑ ุญุงูุฉ A ูุจู ู
ุง A.execute() โ ุณููู A ุจูุนุชู
ุฏ ุนูู B
moduleB.changeModuleAState(moduleA, 1);
moduleA.execute();
ModuleA.execute() ุจูุนุชู
ุฏ ูููุงู ุนูู state ุงุชุญุทู ู
ู module ุชุงูู (ModuleB). ุงูุงุชููู ู
ุชุดุงุจูููุ ูุฃู ุชุบููุฑ ูู ุชุณูุณู ุงูู calls ุจูุบููุฑ ุงููุชูุฌุฉ ุจุดูู ุบูุฑ ู
ุชููุน.ูู module:
- โ ุนูุฏู ู ุณุคูููุฉ ูุงุญุฏุฉ ูุงุถุญุฉ (High cohesion - Functional).
- โ ุจูุนุชู ุฏ ุนูู ุจุงูู ุงูู modules ุจุฃูู ูุฏุฑ (Low coupling - Data only).
- โ ุณูู ุชุณุชุจุฏููุ ุชุฎุชุจุฑูุ ุชููู ู ููุญุฏู.
Exam Question Bank โ Lecture 4
4 ุฃุณุฆูุฉ ุญููููุฉ ู ู Winter 2025 ุนูู Cyclomatic Complexity, Cohesion, Coupling, White-box Testing.
StringUtils? (The class has multiple static String methods, each with at most 1 if/branch.)
StringUtils have? (StringUtils contains multiple static methods all dealing with String operations: toUpper, toLower, etc.)StringUtils ุจุชุณุงูู
ูู ูุธููุฉ ูุงุญุฏุฉ well-defined: String manipulation. ุฏู ุงูู best level of cohesion.
let counter = 0;
class ModuleA { increment() { counter++; } }
class ModuleB { display() { console.log("Count: " + counter); } }
counter ูู global variable ุจุชุดุงุฑู ููู ModuleA ู ModuleB. ุฃู module ูุนุฏูู ูู ุงูู counter ูุชุฃุซุฑ ุงูุจุงูู. ุฏู exactly ุชุนุฑูู ุงูู Common Coupling.
(1) FULL statement coverage, AND
(2) FULL path coverage (not branch coverage)
for a sequential code block with one chained if-else-if structure with 4 distinct paths?
- Statement coverage: ูู ุงูููุฏ ููู ุนุจุงุฑุงุช executed ู ุฑุฉ ุนูู ุงูุฃูู ุจู input ูุงุญุฏุ test case ูุงุญุฏ ููุงูุฉ.
- Path coverage: ู ุญุชุงุฌ test case ููู independent path. ุนุฏุฏ ุงูู paths = V(G). ูู V(G) = 4ุ ู ุญุชุงุฌ 4 test cases.
Cheat Sheet
ูู ุงูู ุนุงุฏูุงุช ูุงูู ุณุชููุงุช ูุงูุชุนุฑููุงุช.
๐งฎ Cyclomatic Complexity
๐ Cohesion โ Best to Worst
๐ Coupling โ 5 Types (El-Ramly)
๐ฏ Golden Rules
Rapid Revision
Flashcards ยท Common Mistakes ยท What the doctor loves to ask.
๐จ Common Mistakes
decisions + 1. ู
ุด ุจุณ ุนุฏุฏ ุงูู ifs.โญ What Dr. El-Ramly Loves to Ask
- Cyclomatic Complexity โ ุจูุฏู class ูุนููู ุชุญุณุจ ุงูู average per function.
- Cohesion type โ ุจูุฏู class ูุนููู ุชุญุฏุฏ type cohesion.
- Coupling type โ ุจูุฏู code snippet (global var, parameter, etc.) ูุนููู ุชุญุฏุฏ type coupling.
- Test cases for coverage โ ู ูุงุฑูุฉ ุจูู statement vs path vs branch coverage.