Created
August 24, 2019 20:03
-
-
Save feynon/85271e3071c59cd00ddcc13cdd5da706 to your computer and use it in GitHub Desktop.
A client should never be forced to implement an interface that it doesn’t use or clients shouldn’t be forced to depend on methods they do not use.
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 manageShapeInterface = fn => ({ | |
type: "manageShapeInterface", | |
calculate: () => fn() | |
}); | |
const circle = radius => { | |
const proto = { | |
radius, | |
type: "Circle", | |
area: args => Math.PI * Math.pow(args.radius, 2) | |
}; | |
const basics = shapeInterface(proto); | |
const abstraccion = manageShapeInterface(() => basics.area()); | |
const composite = Object.assign({}, basics, abstraccion); | |
return Object.assign(Object.create(composite), { radius }); | |
}; | |
const cubo = length => { | |
const proto = { | |
length, | |
type: "Cubo", | |
area: args => Math.pow(args.length, 2), | |
volume: args => Math.pow(args.length, 3) | |
}; | |
const basics = shapeInterface(proto); | |
const complex = solidShapeInterface(proto); | |
const abstraccion = manageShapeInterface( | |
() => basics.area() + complex.volume() | |
); | |
const composite = Object.assign({}, basics, abstraccion); | |
return Object.assign(Object.create(composite), { length }); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment