[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -2,102 +2,158 @@
|
||||
id: wiki-2026-0508-응집도-cohesion
|
||||
title: 응집도 (Cohesion)
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [P-Reinforce-AUTO-2C194C]
|
||||
aliases: [Cohesion, 응집도, Module Cohesion]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
tags: [auto-reinforced]
|
||||
verification_status: applied
|
||||
tags: [software-design, modularity, srp]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-04-20
|
||||
github_commit: "[P-Reinforce] Continuous Worker - 응집도 (Cohesion)"
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: unspecified
|
||||
framework: unspecified
|
||||
language: any
|
||||
framework: any
|
||||
---
|
||||
|
||||
# [[응집도 (Cohesion)|응집도 (Cohesion]]
|
||||
# 응집도 (Cohesion)
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
> 응집도(Cohesion)는 소프트웨어 설계에서 모듈이나 클래스 내의 요소들이 얼마나 밀접하게 관련되어 있고 단일한 목적이나 기능에 집중하고 있는지를 나타내는 척도입니다 [1-3]. 직무의 집합, 세부사항의 수준, 그리고 지역적 유사성의 척도로도 정의됩니다 [4, 5]. 응집도가 높을수록 코드의 가독성과 유지보수성이 향상되며, 반대로 낮을 경우 시스템을 이해하거나 재사용하기 어려워집니다 [3, 6]. 따라서 효과적인 소프트웨어 설계에서는 '**응집도는 높게, 결합도는 낮게**' 유지하는 것이 핵심 원칙입니다 [7, 8].
|
||||
## 매 한 줄
|
||||
> **"매 한 module, 매 한 reason to change"**. 매 module 내부 element 가 매 single purpose 의 향해 의 얼마나 의 tightly 의 related 의 measure. 매 Larry Constantine (1974) 의 7-level taxonomy. 매 SOLID 의 SRP 의 conceptual ancestor.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
**응집도의 정의와 중요성**
|
||||
응집도는 한 클래스나 모듈 내의 모든 요소들이 얼마나 잘 속해 있는지를 보여주는 척도입니다 [2]. 높은 응집도는 해당 모듈이 단일한 기능이나 역할에 집중하고 있음을 뜻하며, 이는 코드의 명확성, 유지보수성, 재사용성, 테스트 용이성을 크게 향상시킵니다 [3, 6]. 반면, 낮은 응집도를 가진 모듈은 여러 역할을 동시에 수행하게 되어 맥락 없이 코드를 오가야 하는 '스파게티 코드'를 유발하며, 기능 수정 시 예상치 못한 부작용(Side Effect)을 발생시켜 유지보수를 어렵게 만듭니다 [6, 9].
|
||||
## 매 핵심
|
||||
|
||||
**응집도의 유형**
|
||||
응집도는 요소들 간의 관련성 성격과 수준에 따라 6가지 주요 형태로 분류할 수 있습니다 [10].
|
||||
* **기능적 응집 (Functional Cohesion):** 모듈 내 모든 요소가 하나의 명확한 일을 성취하기 위해 완벽히 협력하는 경우로, 가장 이상적인 최고 수준의 응집도입니다 [2, 10].
|
||||
* **순차적 응집 (Sequential Cohesion):** 모듈 내 한 요소의 출력이 곧바로 다른 요소의 입력으로 사용되는 밀접한 구조입니다 [2, 10].
|
||||
* **논리적 응집 ([[Logic|Logic]]al Cohesion):** 입력 검증 작업과 같이 유사한 성격을 가진 여러 작업들을 묶어 한 모듈에서 처리하는 형태입니다 [10].
|
||||
* **시간적 응집 (Temporal Cohesion):** 시스템 시작 시 필요한 여러 초기화 작업들처럼, 특정 시간에 동시에 발생하는 작업들을 한 곳에 모아둔 경우입니다 [10].
|
||||
* **절차적 응집 (Procedural Cohesion):** 특정 순서에 따라 순차적으로 실행되어야 하는 작업들을 한 모듈에 모아둔 상태입니다 [10].
|
||||
* **우발적 응집 (Coincidental Cohesion):** 모듈 내 요소들이 논리적 연관성 없이 우연히 한 곳에 모여 있는 형태로, 가장 낮은 수준의 응집도이며 유지보수가 매우 어렵습니다 [10].
|
||||
### 매 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)` |
|
||||
|
||||
**응집도와 결합도의 관계**
|
||||
관심사의 분리([[_뇌와 팔다리의 분리_ - 관심사의 분리 (Separation of Concerns)|Separation of Concerns]])를 성공적으로 적용하기 위해서는 응집력 증가와 결합도 감소라는 두 가지 과정이 반드시 병행되어야 합니다 [3, 5]. 결합도가 다른 모듈에 대한 시스템의 상호 의존도를 의미한다면, 응집도는 모듈 내부의 결속력을 의미합니다 [1, 5]. 공학적으로 우수한 소프트웨어 아키텍처는 같은 역할을 하는 요소들을 가까이 배치하여 **내부 결속력은 극대화(높은 응집도)**하고, **외부 시스템과의 간섭은 최소화(낮은 결합도)**하는 방향을 지향합니다 [5, 7, 11].
|
||||
### 매 Functional cohesion (target)
|
||||
- 매 module 의 모든 element 의 한 well-defined task 의 contribute.
|
||||
- 매 reusable, testable, maintainable.
|
||||
- 매 SRP 의 satisfied.
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
- **과거 데이터와의 충돌:** 자동화 엔진에 의해 매핑된 지식으로, 추후 정밀 검증 필요.
|
||||
- **정책 변화:** Programming & Language 분야의 자동 자산화 수행.
|
||||
### 매 측정 (informal)
|
||||
- 매 module 의 description 의 "and" / "or" 의 포함? → 매 likely low cohesion.
|
||||
- 매 reason to change 의 한 가지? → 매 high cohesion.
|
||||
- 매 LCOM (Lack of Cohesion of Methods) — Chidamber-Kemerer metric.
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- **Related Topics:** [[관심사의 분리 (Separation of Concerns)|관심사의 분리 (Separation of Concerns]], 결합도 (Coupling), [[단일 책임 원칙 (Single Responsibility Principle)|단일 책임 원칙 (Single Responsibility Principle]]
|
||||
- **Projects/Contexts:** [[클린 아키텍처 (Clean Architecture)|클린 아키텍처 (Clean Architecture]], [[마이크로서비스 아키텍처 (MSA)|마이크로서비스 아키텍처 (MSA]]
|
||||
- **Contradictions/Notes:** 소스 전반에 걸쳐 응집도에 대한 상반된 의견은 존재하지 않으며, 모든 소프트웨어 공학 문헌에서 "응집도는 높이고 결합도는 낮춰야 한다"는 일관된 설계 방향을 옹호하고 있습니다.
|
||||
## 💻 패턴
|
||||
|
||||
---
|
||||
*Last updated: 2026-04-18*
|
||||
|
||||
---
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
|
||||
## 💻 코드 패턴 (Code Patterns)
|
||||
|
||||
**패턴 1:** *(TODO: 이 프로젝트 컨벤션 반영한 구조 스켈레톤)*
|
||||
|
||||
```text
|
||||
# TODO
|
||||
### 매 Functional cohesion (best)
|
||||
```python
|
||||
class TaxCalculator:
|
||||
def calculate(self, amount: Decimal, jurisdiction: str) -> Decimal:
|
||||
rate = self._lookup_rate(jurisdiction)
|
||||
return amount * rate
|
||||
```
|
||||
|
||||
## 🤔 의사결정 기준 (Decision Criteria)
|
||||
### 매 Coincidental → split
|
||||
```python
|
||||
# Before — 매 coincidental
|
||||
class Utils:
|
||||
def format_phone(p): ...
|
||||
def calculate_tax(a): ...
|
||||
def send_email(e): ...
|
||||
|
||||
**선택 A를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
# After — 매 functional
|
||||
class PhoneFormatter: ...
|
||||
class TaxCalculator: ...
|
||||
class EmailSender: ...
|
||||
```
|
||||
|
||||
**선택 B를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
### 매 Temporal → procedural / functional
|
||||
```python
|
||||
# Before — 매 temporal "everything at startup"
|
||||
def init():
|
||||
connect_db()
|
||||
load_config()
|
||||
warm_cache()
|
||||
start_metrics()
|
||||
|
||||
**기본값:**
|
||||
> *(TODO)*
|
||||
# After — 매 explicit phases
|
||||
class Bootstrap:
|
||||
def configure(self): load_config()
|
||||
def connect(self): connect_db()
|
||||
def warm(self): warm_cache()
|
||||
def observe(self): start_metrics()
|
||||
```
|
||||
|
||||
## ❌ 안티패턴 (Anti-Patterns)
|
||||
### 매 Logical → polymorphism
|
||||
```python
|
||||
# Before — 매 logical "all I/O"
|
||||
class IOHandler:
|
||||
def read_file(self, p): ...
|
||||
def read_socket(self, s): ...
|
||||
def read_stdin(self): ...
|
||||
|
||||
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
|
||||
# After — 매 functional via interface
|
||||
class Reader(Protocol):
|
||||
def read(self) -> bytes: ...
|
||||
|
||||
class FileReader(Reader): ...
|
||||
class SocketReader(Reader): ...
|
||||
class StdinReader(Reader): ...
|
||||
```
|
||||
|
||||
### 매 LCOM 측정 (Java)
|
||||
```java
|
||||
// 매 ckjm tool / SonarQube 의 LCOM4 metric
|
||||
// LCOM4 = 1 → 매 perfectly cohesive
|
||||
// LCOM4 > 1 → 매 split candidates
|
||||
```
|
||||
|
||||
### 매 Communicational cohesion 예
|
||||
```python
|
||||
class InvoiceReport:
|
||||
def __init__(self, invoice: Invoice):
|
||||
self.invoice = invoice # 매 shared data
|
||||
|
||||
def to_pdf(self): ...
|
||||
def to_csv(self): ...
|
||||
def to_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.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[응집도와 결합도 (Cohesion and Coupling)]]
|
||||
- 변형: [[Functional Cohesion]] · [[Logical Cohesion]]
|
||||
- 응용: [[SOLID]] · [[Single Responsibility Principle]]
|
||||
- Adjacent: [[결합도]] · [[Connascence]] · [[LCOM]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 class / module 의 design review. 매 god class refactoring 의 priority.
|
||||
**언제 X**: 매 trivial DTO / value object — 매 cohesion 의 의 trivially high.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **God class**: 매 매 모든 의 처리 → 매 lowest cohesion.
|
||||
- **Utility dumping ground**: 매 `Helpers`, `Common`, `Misc` 의 class.
|
||||
- **Manager class**: 매 `XxxManager` 의 vague responsibility.
|
||||
- **Feature envy**: 매 method 의 다른 class 의 data 의 access — 매 wrong class 의 의 belong.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified — Constantine & Yourdon, *Structured Design* (1979); Robert C. Martin, *Clean Architecture*.
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — 7 cohesion levels + refactor recipes |
|
||||
|
||||
Reference in New Issue
Block a user