pattern-composite
Patrón Composite: composar objetos en estructuras de árbol y trabajar como objetos individuales. Trigger: Cuando representás parte-todo jerarquías.
- License 许可
- Apache-2.0
- 最近更新
- 2026-08-26
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- pattern-composite
- license
- Apache-2.0
- metadata
- { "author": "gentleman-programming", "version": "1.0" }
- description
- Patrón Composite: composar objetos en estructuras de árbol y trabajar como objetos individuales. Trigger: Cuando representás parte-todo jerarquías.
02 资源文件 1
- 参考文档README.md431 B
03 SKILL.md 正文
Propósito
Componer objetos en estructuras de árbol y trabajar con esas estructuras como si fueran objetos individuales.
Cuándo Usarlo
- Representar jerarquías parte-todo
- Necesitás tratar objetos individuales y compuestos igual
- Operaciones recursivas en árbol
- Sistema de archivos, UI components, organigramas
Estructura
Component (interfaz)
└─ operation()
└─ add(child)
└─ remove(child)
Leaf (objeto simple)
└─ operation()
Composite (contiene hijos)
└─ operation() → for child in children: child.operation()
└─ add/remove children
Ejemplo
class File(ABC):
def get_size(self): pass
class FileLeaf(File):
def __init__(self, size):
self.size = size
def get_size(self): return self.size
class Folder(File):
def __init__(self):
self.children = []
def add(self, file):
self.children.append(file)
def get_size(self):
return sum(child.get_size() for child in self.children)
# Uso - todos tratan igual
root = Folder()
root.add(FileLeaf(100))
root.add(FileLeaf(200))
subfolder = Folder()
subfolder.add(FileLeaf(50))
root.add(subfolder)
print(root.get_size()) # 350
Código Smell que Resuelve
- Tratar diferente objetos simples vs compuestos
- Código condicional para verificar tipo
Operaciones Típicas
- Recursive size calculation
- Tree traversal
- Apply operation to all
- Count elements
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.