From a624d544fe8ec46992c97a321bf7cc37d2085cb1 Mon Sep 17 00:00:00 2001 From: davidvujic Date: Mon, 30 Jan 2017 13:16:28 +0100 Subject: [PATCH 1/2] refactor: Liskov Substitution - width/height/length as constructor parameters --- README.md | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index b52518f9..6199955b 100644 --- a/README.md +++ b/README.md @@ -1252,22 +1252,14 @@ class Shape { } render(area) { - // ... + // .. } } class Rectangle extends Shape { - constructor() { + constructor(width, height) { super(); - this.width = 0; - this.height = 0; - } - - setWidth(width) { this.width = width; - } - - setHeight(height) { this.height = height; } @@ -1277,12 +1269,8 @@ class Rectangle extends Shape { } class Square extends Shape { - constructor() { + constructor(length) { super(); - this.length = 0; - } - - setLength(length) { this.length = length; } @@ -1293,21 +1281,12 @@ class Square extends Shape { function renderLargeShapes(shapes) { shapes.forEach((shape) => { - switch (shape.constructor.name) { - case 'Square': - shape.setLength(5); - break; - case 'Rectangle': - shape.setWidth(4); - shape.setHeight(5); - } - - const area = shape.getArea(); - shape.render(area); - }); -} + const area = shape.getArea(); + shape.render(area); + }); + } -const shapes = [new Rectangle(), new Rectangle(), new Square()]; +const shapes = [new Rectangle(4, 5), new Rectangle(4, 5), new Square(5)]; renderLargeShapes(shapes); ``` **[⬆ back to top](#table-of-contents)** From 90e9b243628f1baffd32352b5bb965cc98e67a27 Mon Sep 17 00:00:00 2001 From: davidvujic Date: Mon, 30 Jan 2017 13:18:07 +0100 Subject: [PATCH 2/2] fix: typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6199955b..5cca67d8 100644 --- a/README.md +++ b/README.md @@ -1252,7 +1252,7 @@ class Shape { } render(area) { - // .. + // ... } }