This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AreaCalculator { | |
constructor (shapes) { | |
this.shapes = shapes | |
} | |
sum () { | |
return this.shapes | |
.map((shape) => { | |
if (shape instanceof Circle) { | |
return 2 * Math.PI * Math.pow(shape.radius, 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const circle = new Circle(7) | |
const square = new Square(3) | |
const shapes = [circle, square] | |
const areaCalculator = new AreaCalculator(shapes) | |
const areaOutput = new CalculatorOutput(areaCalculator) | |
// now we can access each output type | |
console.log(output.toString()) | |
console.log(output.toJSON()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AreaCalculator { | |
constructor (shapes) { | |
this.shapes = shapes | |
} | |
sum () { | |
// logic to calculate the sum of the areas of the provided shapes | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Circle { | |
constructor (radius) { | |
this.radius = radius | |
} | |
} | |
class Square { | |
constructor (length) { | |
this.length = length | |
} |
NewerOlder