Commit de7ac3db authored by Fernandez Teodoro's avatar Fernandez Teodoro

ENTREGA REFACTORING SOLID

parents
Pipeline #45 failed with stages
in 9 seconds

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

<<<<<<< HEAD
### Laboratorio de Programación y lenguajes 2021
=======
### Laboratorio de Programación y lenguajes
>>>>>>> ad4a3b263ac940265ca637bed056c66f9dc56bf1
### Taller Refactoring
-Para aplicar DIP y LSP en ambos casos tuve que crear una clase de la cual extiendan sus "especializaciones" en las cuales esas extensiones tenian que definir el funcionamiento de la misma (aplicacion de LSP) y crear una Factoria para instanciar los objetos a traves de ella ( DIP )
+function createRender
+class Render
+class RenderHtml
+class RenderPlainText
+function createCurrency
+class Currency
+class CurrencyARS
+class CurrencyUSD
-Para verificar el polimorfismo solo cree 2 casos, uno en el que se usaban texto plano con ARS y otro donde se usaba html con ARS
-En esta entrega del taller realice bastantes cambios en la forma de ver el codigo, si bien hubo incovenientes, se resolvieron con el aporte de las consultas hechas por compañeros (imprimir el borderau con pesos argentinos)
<<<<<<< HEAD
const { setWorldConstructor } = require("@cucumber/cucumber");
module.exports = createStatementData = function createStatementData(
invoice,
plays
) {
let statementData = {};
statementData.customer = invoice.customer;
statementData.performances = invoice.performances.map(enrichPerformance);
statementData.totalAmount = totalAmount(statementData.performances);
statementData.totalVolumenCredits = totalVolumenCredits(
statementData.performances
);
return statementData;
function enrichPerformance(aPerformance) {
const calculator = createPerformanceCalculator(
aPerformance,
playFor(aPerformance)
);
const result = Object.assign({}, aPerformance);
result.play = playFor(result);
result.amount = calculator.amount;
result.volumeCredits = calculator.volumeCredits;
return result;
}
function playFor(aPerformace) {
return plays[aPerformace.playID];
}
function totalAmount(somePerformances) {
return somePerformances.reduce(
(prev, aPerformance) => prev + aPerformance.amount,
0
);
}
function totalVolumenCredits(somePerformances) {
return somePerformances.reduce(
(prev, aPerformance) => prev + aPerformance.volumeCredits,
0
);
}
function createPerformanceCalculator(aPerformance, aPlay) {
switch (aPlay.type) {
case "tragedy":
return new TragedyCalculator(aPerformance, aPlay);
case "comedy":
return new ComedyCalculator(aPerformance, aPlay);
default:
throw new Error(`tipo desconocido: ${this.play.type}`);
}
}
};
class PerformanceCalculator {
constructor(aPerformance, aPlay) {
this.performance = aPerformance;
this.play = aPlay;
}
get amount() {
throw new Error(`responsabilidad de subclase`);
}
get volumeCredits() {
throw new Error(`responsabilidad de subclase`);
}
}
class TragedyCalculator extends PerformanceCalculator {
get amount() {
let result = 40000;
if (this.performance.audience > 30) {
result += 1000 * (this.performance.audience - 30);
}
return result;
}
get volumeCredits() {
return volumeCreditsComposer(this.performance.audience);
}
}
class ComedyCalculator extends PerformanceCalculator {
get amount() {
let result = 30000;
if (this.performance.audience > 20) {
result += 10000 + 500 * (this.performance.audience - 20);
}
result += 300 * this.performance.audience;
return result;
}
get volumeCredits() {
return (
volumeCreditsComposer(this.performance.audience) +
Math.floor(this.performance.audience / 5)
);
}
}
function volumeCreditsComposer(aAudience) {
return Math.max(aAudience - 30, 0);
}
=======
module.exports = createStatementData = function (invoice, plays) {
const result = {};
result.customer = invoice.customer;
result.performances = invoice.performances.map(enrichPerformance);
result.totalAmount = totalAmount(result.performances);
result.totalVolumeCredits = totalVolumeCredits(result.performances);
return result;
function enrichPerformance(aPerformance) {
const calculator = createPerformanceCalculator(aPerformance, playFor(aPerformance));
const result = Object.assign({}, calculator.performance);
result.play = calculator.play;
result.amount = calculator.amount;
result.volumeCredits = calculator.volumeCredits;
return result;
}
function playFor(aPerformance) {
return plays[aPerformance.playID];
}
function totalAmount(somePerformances) {
return somePerformances.reduce(
(result, aPerformance) => result + aPerformance.amount, 0
);
}
function totalVolumeCredits(somePerformances) {
return somePerformances.reduce(
(result, aPerformance) => result + aPerformance.volumeCredits, 0
);
}
}
function createPerformanceCalculator(aPerformance, aPlay) {
switch (aPlay.type) {
case "tragedy": return new TragedyCalculator(aPerformance, aPlay);
case "comedy": return new ComedyCalculator(aPerformance, aPlay);
default:
throw new Error(`unknown type: ${this.play.type}`);
}
}
class PerformanceCalculator {
constructor(aPerformance, aPlay) {
this.performance = aPerformance;
this.play = aPlay;
}
get amount() {
throw new Error(`subclass responsability`);
}
get volumeCredits() {
return Math.max(this.performance.audience - 30, 0);
}