Skip to main content

applying-design-patterns

Applies GoF and DDD design patterns in TypeScript: Factory, Repository, Strategy, Adapter, Decorator, Facade, Observer, Command, Specification. Use when picking the right structure for a feature or refactoring duplicated logic.

소스 정보

저장소
j4flmao/agent_skills_nodejs_nestjs
최근 소스 활동
2026년 5월 3일 03:46
감지된 SKILL.md 언어
영어
스타
1
포크
0

설치 방법

기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.

소스 파일 검토

설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.

파일 탐색기
5 개 파일

SKILL.md 표시 중

SKILL.md
소스 지침 · 읽기 전용 미리보기
name
applying-design-patterns
description
Applies GoF and DDD design patterns in TypeScript: Factory, Repository, Strategy, Adapter, Decorator, Facade, Observer, Command, Specification. Use when picking the right structure for a feature or refactoring duplicated logic.
# Applying Design Patterns ## When to use - Picking the right structure for a new feature - Refactoring duplicated logic - Need pluggable algorithms or interchangeable implementations ## Core rules 1. Use patterns by name: Factory, Repository, Strategy, Adapter, Decorator, Facade, Observer, Command, Specification 2. Patterns serve the business, not the other way around 3. Prefer composition over inheritance 4. All pattern implementations must be OOP classes with explicit typing ## Reference shape (TypeScript) ### Factory Pattern ```typescript export class UserFactory { static createRegular(id: string, email: string): User { return User.create(id, Email.create(email), ['user']); } static createAdmin(id: string, email: string): User { return User.create(id, Email.create(email), ['user', 'admin']); } } ``` ### Strategy Pattern ```typescript export interface PricingStrategy { calculate(base: number): number; } export class DiscountPricing implements PricingStrategy { constructor(private discount: number) {} calculate(base: number): number { return base - this.discount; } } ``` ### Repository Pattern ```typescript export interface OrderRepository { findById(id: string): Promise<Order | null>; save(order: Order): Promise<Order>; } ``` ## Examples — Do ```typescript // Command pattern class CreateOrderCommand { constructor(public readonly userId: string, public readonly items: OrderItem[]) {} } class CreateOrderHandler { async handle(cmd: CreateOrderCommand): Promise<Result<Order, AppError>> { ... } } ``` ## Examples — Don't ```typescript // ❌ Over-engineering: simple logic doesn't need patterns class UserBuilder { setName(n: string) { this.name = n; return this; } } ``` ## Checklist - [ ] Pattern matches the problem (Factory for creation, Strategy for algorithms) - [ ] All pattern classes are OOP with explicit types - [ ] No over-engineering simple logic See [reference/pattern-examples.md](./reference/pattern-examples.md) for full patterns.
GitHub에서 보기