안전한 코드 리팩토링 패턴 및 레거시 현대화 전략
Scanned 9/2/2026
Install to Claude Code
npx -y skills add Insajin/autopus-adk --skill refactoring --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Refactoring?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/insajin-refactoring)More formats (shields.io, HTML) on the badges page.
---
name: refactoring
description: 안전한 코드 리팩토링 패턴 및 레거시 현대화 전략
compatibility: omp
---
# Refactoring Skill
기존 동작을 보존하면서 코드 구조를 개선하는 스킬입니다.
## 핵심 원칙
1. **테스트 먼저**: 리팩토링 전 기존 동작을 테스트로 보호
2. **작은 단계**: 한 번에 하나의 변환만 적용
3. **행동 보존**: 외부 동작 변경 금지
4. **기능 변경 분리**: 리팩토링 커밋과 기능 변경 커밋 분리
## 안전한 리팩토링 패턴
### Extract Function
```go
// Before: 긴 함수
func processOrder(order *Order) error {
// 검증 로직 20줄
// 계산 로직 15줄
// 저장 로직 10줄
}
// After: 책임 분리
func processOrder(order *Order) error {
if err := validateOrder(order); err != nil {
return err
}
total := calculateTotal(order)
return saveOrder(order, total)
}
```
### Extract Interface
```go
// Before: 구체 타입에 의존
func SendEmail(client *SMTPClient, msg string) { ... }
// After: 인터페이스로 추상화
type EmailSender interface {
Send(msg string) error
}
func SendEmail(sender EmailSender, msg string) { ... }
```
### Replace Conditional with Polymorphism
```go
// Before: switch/if 분기
func price(t string) int {
switch t {
case "basic": return 100
case "pro": return 200
}
}
// After: 인터페이스 다형성
type Plan interface {
Price() int
}
```
### Rename (전체 프로젝트)
```bash
# 호출자 확인 후 변경
grep -r "oldName" --include="*.go"
# IDE/도구 활용 권장 (gopls rename)
```
## 레거시 현대화 전략
### Strangler Fig Pattern
1. 새 구현체를 기존 시스템 옆에 배치
2. 트래픽을 점진적으로 새 구현체로 이전
3. 완전 이전 후 구 구현체 제거
### Branch by Abstraction
1. 변경 대상에 인터페이스 추출
2. 기존 구현체를 인터페이스 구현으로 래핑
3. 새 구현체 작성
4. 의존성 주입으로 교체
## 데드코드 제거
확인 절차:
```bash
# 사용되지 않는 함수 탐지
go vet ./...
# 호출자 검색
grep -r "functionName" --include="*.go" | grep -v "_test.go"
```
제거 원칙:
- 호출자 0개 확인 후 제거
- 주석 처리 대신 완전 삭제 (git 히스토리에 보존됨)
- `// removed` 주석 남기지 않기
## 리팩토링 안전 체크리스트
- [ ] 기존 테스트 모두 통과
- [ ] 특성 테스트 추가 (기존 동작 보호)
- [ ] 각 단계 후 테스트 실행
- [ ] 리팩토링과 기능 변경 커밋 분리
- [ ] 변경 전후 동작 동일 확인
- [ ] fan_in >= 3 함수에 @AX:ANCHOR 태그
Is this your skill, or is something wrong with this listing? . Author removals are honored within 72 hours.
No comments yet. Be the first to comment!