1
// ==========================================
// SIMULACIÓN DE MÓDULO 1: /models/Cliente.js
// ==========================================
const ModuloCliente = (() => {
class Cliente {
constructor(id, nombre, email) {
this.id = id;
this.nombre = nombre;
this.email = email;
}
obtenerFicha() {
return `Cliente: ${this.nombre} <${this.email}>`;
}
}
return { Cliente };
})();
// ==========================================
// SIMULACIÓN DE MÓDULO 2: /services/Facturacion.js
// ==========================================
const ModuloFacturacion = (() => {
class ServicioFacturacion {
generarFactura(cliente, items) {
const subtotal = items.reduce((acc, item) => acc + item.precio, 0);
const iva = subtotal * 0.19;
const total = subtotal + iva;
return {
folio: "FAC-" + Math.floor(1000 + Math.random() * 9000),
cliente: cliente.obtenerFicha(),
articulos: items.length,
subtotal: subtotal.toFixed(2),
total: total.toFixed(2),
fecha: new Date().toLocaleDateString()
};
}
}
return { ServicioFacturacion };
})();
// ==========================================
// CÓDIGO PRINCIPAL: /app.js (Importa y Orquesta)
// ==========================================
const { Cliente } = ModuloCliente;
const { ServicioFacturacion } = ModuloFacturacion;
console.log("=== ARQUITECTURA MODULAR DE CLASES ===");
const nuevoCliente = new Cliente(1, "Valeria Torres", "[email protected]");
const servicio = new ServicioFacturacion();
const carrito = [
{ nombre: "Curso Arquitectura JS", precio: 89.99 },
{ nombre: "E-book Patrones de Diseño", precio: 29.99 }
];
const facturaEmitida = servicio.generarFactura(nuevoCliente, carrito);
console.log("✔ Factura generada por el módulo de facturación:");
console.log(`• Folio: ${facturaEmitida.folio}`);
console.log(`• Destinatario: ${facturaEmitida.cliente}`);
console.log(`• Total a Pagar (+IVA): $${facturaEmitida.total} USD`);
console.log(`• Fecha de Emisión: ${facturaEmitida.fecha}`);
Haz clic para editar este código