Skip to content

Instantly share code, notes, and snippets.

@kudapara
Last active April 18, 2018 19:19
Show Gist options
  • Save kudapara/b37afa1b31f94430861e530b15c04f89 to your computer and use it in GitHub Desktop.
Save kudapara/b37afa1b31f94430861e530b15c04f89 to your computer and use it in GitHub Desktop.
Code that does not violate SRP
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