Last active
April 18, 2018 19:19
-
-
Save kudapara/b37afa1b31f94430861e530b15c04f89 to your computer and use it in GitHub Desktop.
Code that does not violate SRP
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 | |
} | |
} | |
class CalculatorOutput { | |
constructor(areaCalculator) { | |
this.areaCalculator = areaCalculator | |
} | |
toString () { | |
return new String(this.areaCalculator.sum()) | |
} | |
toJSON () { | |
return { | |
sum: this.areaCalculator.sum() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment