1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| class RoundHole { constructor() {} getRadius() {} fits(peg) { return this.Radius() >= peg.getRadius() } } class RoundPeg { constructor(width) { this.width = w } getRadius() {} }
class SquarePeg { constructor() {} getWidth() {} }
class SquarePegAdapter extends RoundPeg { constructor() { this.peg = peg } getRadius() { return this.peg.getWidth()* Math.sqrt(2) /2 } }
let hole = new RoundHole(5)
let smallSqpeg = new SquarePeg(5) let largeSqpeg = new SquarePeg(10) let smallAdapter = new SquarePegAdapter(smallSqpeg) let largeAdapter = new SquarePegAdapter(largeSqpeg)
hole.fits(smallAdapter) hole.fits(largeAdapter)
|