"매 system 을 서로 겹치지 않는 concern 단위로 쪼개 각각이 독립 변경 가능하도록 한다". Dijkstra (1974) — 매 modularity 의 근본 원리. 매 layer / module / function / file 모든 scale 에 적용. 매 변경의 locality + 매 testability 를 동시에 얻는다.
매 핵심
매 SoC 의 본질
Concern: 매 system 이 처리하는 distinct topic (UI, persistence, billing, auth).
Separation: 매 concern 별로 코드/모듈/팀/배포 단위 분리.
Independent change: concern A 의 변경이 B 의 코드 수정 X.
매 적용 scale
Function: 매 single responsibility (SRP).
Module: 매 cohesion 높음 + coupling 낮음.
Layer: presentation / business / persistence (layered arch).
// domain port (concern: business)
exportinterfaceOrderRepo{save(o: Order):Promise<void>;findById(id: OrderId):Promise<Order|null>;}// adapter (concern: infra)
exportclassPostgresOrderRepoimplementsOrderRepo{/* SQL */}exportclassInMemoryOrderRepoimplementsOrderRepo{/* test */}
AOP (cross-cutting) — Spring
@Aspect@ComponentclassTxAspect{@Around("@annotation(Transactional)")ObjectinTx(ProceedingJoinPointpjp)throwsThrowable{vartx=txManager.begin();try{varr=pjp.proceed();tx.commit();returnr;}catch(Throwablet){tx.rollback();throwt;}}}// 매 business code 에서 tx 코드 누설 X
Bounded context (microservice 단위)
billing-service/ ← 매 invoice, charge
inventory-service/ ← 매 stock
shipping-service/ ← 매 carrier integration
# 매 각자 DB, 각자 deploy, 각자 schema
매 결정 기준
상황
Approach
매 small script
function-level SRP 만
매 medium app
layered + module 단위
매 complex domain
hexagonal + bounded context
매 large org
microservice + team boundary
매 cross-cutting (log, tx, auth)
AOP / middleware / interceptor
기본값: 매 layered + DI + interface boundary. 매 over-fragmentation (매 1 함수 1 파일) 의 X.
🔗 Graph
부모: Software Design Principles
변형: Single Responsibility Principle (SRP) · Modularity