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.

Informations de source

Dépôt
j4flmao/agent_skills_nodejs_nestjs
Dernière activité de la source
3 mai 2026 à 03:46
Langue détectée de SKILL.md
anglais
Étoiles
1
Forks
0

Options d'installation

Le prompt qui vérifie d'abord la source est sélectionné par défaut. Vous pouvez passer à une commande directe ou télécharger une copie locale.

Vérifiez les fichiers source

Lisez SKILL.md et les fichiers associés affichés par SkillsMP avant de décider de l'installer.

Explorateur de fichiers
5 fichiers

Affichage de SKILL.md

SKILL.md
Instructions source · Aperçu en lecture seule
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.
Voir sur GitHub