"매 한 module, 매 한 reason to change". 매 module 내부 element 가 매 single purpose 의 향해 의 얼마나 의 tightly 의 related 의 measure. 매 Larry Constantine (1974) 의 7-level taxonomy. 매 SOLID 의 SRP 의 conceptual ancestor.
매 핵심
매 7 levels of cohesion (low → high)
Level
매 의미
예
Coincidental
매 unrelated
Util.java kitchen sink
Logical
매 same category
IOHandler (file + net + console)
Temporal
매 same time
init() 의 mixed setup
Procedural
매 same flow
step1 → step2 → step3
Communicational
매 same data
report 의 multiple formatting
Sequential
매 output → input
parse → validate → transform
Functional
매 single task
calculateTax(invoice)
매 Functional cohesion (target)
매 module 의 모든 element 의 한 well-defined task 의 contribute.
매 reusable, testable, maintainable.
매 SRP 의 satisfied.
매 측정 (informal)
매 module 의 description 의 "and" / "or" 의 포함? → 매 likely low cohesion.
매 reason to change 의 한 가지? → 매 high cohesion.
매 LCOM (Lack of Cohesion of Methods) — Chidamber-Kemerer metric.
# Before — 매 coincidentalclassUtils:defformat_phone(p):...defcalculate_tax(a):...defsend_email(e):...# After — 매 functionalclassPhoneFormatter:...classTaxCalculator:...classEmailSender:...
매 Temporal → procedural / functional
# Before — 매 temporal "everything at startup"definit():connect_db()load_config()warm_cache()start_metrics()# After — 매 explicit phasesclassBootstrap:defconfigure(self):load_config()defconnect(self):connect_db()defwarm(self):warm_cache()defobserve(self):start_metrics()
매 Logical → polymorphism
# Before — 매 logical "all I/O"classIOHandler:defread_file(self,p):...defread_socket(self,s):...defread_stdin(self):...# After — 매 functional via interfaceclassReader(Protocol):defread(self)->bytes:...classFileReader(Reader):...classSocketReader(Reader):...classStdinReader(Reader):...
매 LCOM 측정 (Java)
// 매 ckjm tool / SonarQube 의 LCOM4 metric// LCOM4 = 1 → 매 perfectly cohesive// LCOM4 > 1 → 매 split candidates
매 Communicational cohesion 예
classInvoiceReport:def__init__(self,invoice:Invoice):self.invoice=invoice# 매 shared datadefto_pdf(self):...defto_csv(self):...defto_json(self):...
매 결정 기준
상황
Approach
매 class 의 method 의 의 unrelated
매 Split into multiple classes
매 method 의 의 multiple responsibilities
매 Extract method, then class
매 utility class 의 grow
매 Domain-specific helper 의 의 split
매 god class 의 LCOM 의 high
매 Refactor by responsibility
기본값: 매 functional cohesion 의 추구. 매 SRP — 매 한 class, 매 한 reason to change.