Files
2nd/10_Wiki/Topic_Programming/Architecture/Single Responsibility Principle (SRP).md
T
Antigravity Agent 9148c358d0 docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를
Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류.

- 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로
  자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거,
  동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거.
- 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming,
  Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business,
  Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로,
  나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는
  title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백).
  원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지.
- 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서.
- 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는
  지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지.
- Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경.
- 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
2026-07-05 00:33:48 +09:00

5.5 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-single-responsibility-principle- Single Responsibility Principle (SRP) 10_Wiki/Topics verified self
SRP
Single Responsibility
단일 책임 원칙
none A 0.9 applied
oop
design-principles
solid
clean-code
2026-05-10 pending
language framework
typescript none

Single Responsibility Principle (SRP)

매 한 줄

"매 클래스(모듈)는 매 단 하나의 변경 이유를 가져야 한다". SOLID의 S. Robert C. Martin은 매 후기에 매 정의를 매 *"하나의 actor에게만 책임진다"*로 매 정련 — 즉 매 같은 stakeholder의 요구사항만 매 그 모듈에 매 모인다. 2026년에도 매 module/class boundary 결정의 매 first heuristic.

매 핵심

매 정의 (refined)

  • "Reason to change" → "Actor (stakeholder group)".
  • 매 다른 actor가 매 같은 모듈을 매 다른 방향으로 매 당기면 매 SRP 위반.

매 신호

  • 매 클래스 이름에 "and"/"또".
  • 매 import block 매 두 다른 도메인에서.
  • 매 메서드 절반은 매 DB, 절반은 매 UI.
  • 매 PR에서 매 매번 매 다른 팀이 review.

매 응용

  1. 매 service / repository / presenter 분리.
  2. 매 React: 매 hook 분리 (useData / useUI).
  3. 매 microservices boundary.
  4. 매 LLM agent: 매 tool별 분리.

💻 패턴

매 Before — 책임 혼재

class Report {
  data: Row[];
  load(file: string) { /* CSV 파싱 */ }      // 매 IO actor
  calculate() { /* 매 도메인 로직 */ }        // 매 회계 actor
  printPdf() { /* 매 PDF 렌더 */ }            // 매 publishing actor
  email(to: string) { /* SMTP */ }            // 매 ops actor
}

매 After — actor별 분리

class CsvLoader { load(file: string): Row[] { /* ... */ return []; } }
class Reporter { calculate(rows: Row[]): Stats { /* ... */ return {} as Stats; } }
class PdfRenderer { render(stats: Stats): Buffer { /* ... */ return Buffer.from(""); } }
class EmailSender { send(to: string, attachment: Buffer): Promise<void> { return Promise.resolve(); } }

// 매 orchestration
async function generateAndSend(file: string, to: string) {
  const rows = new CsvLoader().load(file);
  const stats = new Reporter().calculate(rows);
  const pdf = new PdfRenderer().render(stats);
  await new EmailSender().send(to, pdf);
}

매 React hook 분리

// X — fat hook
function useUserPage(id: string) {
  const [user, setUser] = useState<User|null>(null);
  const [open, setOpen] = useState(false);
  useEffect(() => { fetch(`/api/users/${id}`).then(r => r.json()).then(setUser); }, [id]);
  return { user, open, setOpen };
}

// O — actor 분리
function useUser(id: string) {
  return useQuery(["user", id], () => fetch(`/api/users/${id}`).then(r => r.json()));
}
function useDisclosure(initial = false) {
  const [open, setOpen] = useState(initial);
  return { open, openIt: () => setOpen(true), closeIt: () => setOpen(false) };
}

매 NestJS — controller / service / repo

@Controller("orders")
class OrderController {
  constructor(private svc: OrderService) {}
  @Post() place(@Body() dto: PlaceDto) { return this.svc.place(dto); }
}

@Injectable()
class OrderService {
  constructor(private repo: OrderRepo, private mailer: Mailer) {}
  async place(dto: PlaceDto) {
    const o = await this.repo.create(dto);
    await this.mailer.send(o.user, "ordered");
    return o;
  }
}

@Injectable()
class OrderRepo {
  async create(dto: PlaceDto) { /* DB */ return {} as Order; }
}

매 Module boundary (file-level SRP)

src/
  payment/         # 매 payment actor
    PaymentService.ts
    StripeAdapter.ts
  shipping/        # 매 logistics actor
    ShippingService.ts
    FedexAdapter.ts

매 LLM agent — tool SRP

const tools = [
  { name: "search_web",      handler: searchWeb },     // 매 retrieval actor
  { name: "send_email",      handler: sendEmail },     // 매 messaging actor
  { name: "create_calendar", handler: createCalendar } // 매 scheduling actor
];
// 매 한 tool은 매 한 가지 책임만.

매 결정 기준

상황 Approach
매 새 기능 추가 시 매 두 actor 영향 매 분리.
매 클래스가 매 두 다른 ticket queue로 routing 매 SRP 위반 신호.
매 100줄 이내 매 단일 actor 매 그대로 유지.
매 분리 이후 매 cross-talk 폭증 매 over-split. 매 통합 검토.

기본값: 매 actor 매 따라 매 split. 매 line count 기준 X.

🔗 Graph

🤖 LLM 활용

언제: 매 클래스 split 결정, 매 module boundary, 매 PR review 시 책임 혼재 탐지. 언제 X: 매 tiny script.

안티패턴

  • 매 line count 기반 split: 매 actor 무시 → 매 artificial.
  • 매 method 1개 = class 1개 강박: 매 noise.
  • 매 god class 유지 (anti).
  • 매 SRP를 매 layered "service/repo" 만으로 해석: 매 layer 안에서도 매 actor 분리 필요.

🧪 검증 / 중복

  • Verified (R.C. Martin, Clean Architecture, ch. SRP refined).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — actor-based SRP + before/after refactor patterns