This file contains 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 | |
} |
This file contains 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 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 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 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 | |
} | |
area () { | |
return 2 * Math.PI * Math.pow(shape.radius, 2) | |
} | |
} |
This file contains 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 | |
} | |
area () { | |
return 2 * Math.PI * Math.pow(shape.radius, 2) | |
} | |
} |
This file contains 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 Shape { | |
constructor () {} | |
area () {} | |
volume () {} | |
} | |
class Triangle extends Shape { | |
constructor (base, height) { | |
this.base = base | |
this.height = height |
This file contains 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 Shape { | |
constructor () {} | |
area () {} | |
} | |
class SolidShape { | |
constructor () {} | |
volume () {} | |
} |
This file contains 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 Shape { | |
constructor () {} | |
setColor(color) { | |
this.color = color | |
} | |
} | |
class Picture { | |
constructor (color) { | |
this.shape = new Shape() |
This file contains 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 Shape { | |
constructor () {} | |
setColor (color) { | |
this.color = color | |
} | |
} | |
class Triangle extends Shape { | |
constructor (base, height) { |
OlderNewer