| Patrón | Propósito | Cuándo Usar | Código Rápido |
|---|---|---|---|
| Singleton | Una sola instancia en toda la app | Config global, DB connection, cache | if (Instance.instance) return Instance.instance; |
| Factory | Crear objetos sin especificar clase exacta | Múltiples tipos de objetos relacionados | static create(type) { switch(type) {...} } |
| Prototype | Clonar objetos existentes | Creación costosa, necesitas copias | clone() { return new Class(...this.props); } |
| Patrón | Propósito | Cuándo Usar | Código Rápido |
|---|---|---|---|
| Proxy | Controlar acceso a objetos | Validación, logging, lazy loading | new Proxy(obj, { get() {}, set() {} }) |
| Module | Encapsular código relacionado | Organización, evitar scope global | export const func = () => {}; |
| Mixin | Agregar funcionalidad sin herencia | Compartir comportamiento entre clases | Object.assign(Class.prototype, mixin); |
| Flyweight | Compartir datos para ahorrar memoria | Muchos objetos similares | if (cache[key]) return cache[key]; |
| Patrón | Propósito | Cuándo Usar | Código Rápido |
|---|---|---|---|
| Observer | Notificar cambios a suscriptores | Eventos, actualizaciones reactivas | notify(data) { observers.forEach(o => o.update(data)); } |
| Strategy | Intercambiar algoritmos dinámicamente | Múltiples formas de hacer lo mismo | setStrategy(strategy) { this.strategy = strategy; } |
| Mediator | Centralizar comunicación entre objetos | Evitar acoplamiento directo | send(msg, from, to) { to.receive(msg, from); } |
| Patrón | Propósito | Código Rápido |
|---|---|---|
| Dynamic Import | Cargar módulos bajo demanda | const mod = await import('./module.js'); |
| Import on Interaction | Cargar al interactuar | btn.onclick = async () => { const mod = await import('./mod.js'); } |