pattern-prototype
Patrón Prototype: copiar objetos existentes sin depender de sus clases. Trigger: Cuando crear objetos es costoso o complejo.
- License 许可
- Apache-2.0
- 最近更新
- 2026-08-26
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- pattern-prototype
- license
- Apache-2.0
- metadata
- { "author": "gentleman-programming", "version": "1.0" }
- description
- Patrón Prototype: copiar objetos existentes sin depender de sus clases. Trigger: Cuando crear objetos es costoso o complejo.
02 资源文件 1
- 参考文档README.md431 B
03 SKILL.md 正文
Propósito
Copiar objetos existentes sin que el código dependa de sus clases.
Cuándo Usarlo
- Crear objetos es costoso (DB call, network, cálculo)
- Evitar subclases para crear copias
- Necesitás copiar objetos sin conocer su tipo exacto
Estructura
Prototype (interfaz)
└─ clone() → Prototype
ConcretePrototypeA
└─ clone() → new ConcretePrototypeA(self)
ConcretePrototypeB
└─ clone() → new ConcretePrototypeB(self)
Ejemplo
import copy
class Document:
def __init__(self, title, content):
self.title = title
self.content = content
def clone(self):
return copy.deepcopy(self)
# Uso
original = Document("Report", "Content here...")
clone = original.clone()
clone.title = "Report Copy"
Código Smell que Resuelve
- Clonar objetos mediante subclases
- Creación costosa de objetos similares
- Código repetido de creación
Shallow vs Deep Copy
# Shallow - comparte referencias
copy.copy(obj)
# Deep - crea copia independiente
copy.deepcopy(obj)
Casos de Uso Reales
- Templates de documentos
- Configuraciones por defecto
- Clonar entidades en games
- Cache de objetos
Recursos
04 同仓库更多 Skills
zustand-5
Zustand 5 state management patterns. Trigger: When managing React state with Zustand.
zod-4
Zod 4 schema validation patterns. Trigger: When using Zod for validation - breaking changes from v3.
x-bookmark-quote-posts
Workflow para revisar bookmarks de X/Twitter y convertirlos en drafts de quote posts. Accede a la sección de bookmarks vía browser headless, extrae posts recientes, y genera drafts con voz personal del usuario. No publica ni muta X — solo genera contenido para revisión. Trigger: X bookmarks, Twitter bookmarks, quote posts, bookmark automation, crear quote posts, revisar bookmarks, growth content X.
writing-skills
Use when creating new skills, editing existing skills, or verifying skills work before deployment
writing-plans
Use when you have a spec or requirements for a multi-step task, before touching code
work-unit-commits
Plan commits as reviewable work units. Trigger: implementation, commit splitting, chained PRs, or keeping tests and docs with code.