From 1456a97ddf35ae955ee88b2f006a42ff45a645ac Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Mon, 27 Nov 2017 11:03:45 +0300 Subject: [PATCH] add prifix for getters --- README.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index eaa8ab5..1e16064 100644 --- a/README.md +++ b/README.md @@ -1647,7 +1647,7 @@ class Rectangle $this->height = $height; } - public function area(): int + public function getArea(): int { return $this->width * $this->height; } @@ -1672,7 +1672,7 @@ function printArea(Rectangle $rectangle): void $rectangle->setHeight(5); // BAD: Will return 25 for Square. Should be 20. - echo sprintf('%s has area %d.', get_class($rectangle), $rectangle->area()).PHP_EOL; + echo sprintf('%s has area %d.', get_class($rectangle), $rectangle->getArea()).PHP_EOL; } $rectangles = [new Rectangle(), new Square()]; @@ -1698,17 +1698,17 @@ class Rectangle $this->height = $height; } - public function width(): int + public function getWidth(): int { return $this->width; } - public function height(): int + public function getHeight(): int { return $this->height; } - public function area(): int + public function getArea(): int { return $this->width * $this->height; } @@ -1724,7 +1724,7 @@ class Square extends Rectangle function printArea(Rectangle $rectangle): void { - echo sprintf('%s has area %d.', get_class($rectangle), $rectangle->area()).PHP_EOL; + echo sprintf('%s has area %d.', get_class($rectangle), $rectangle->getArea()).PHP_EOL; } $rectangles = [new Rectangle(4, 5), new Square(5)]; @@ -1748,7 +1748,7 @@ A square, a rectangle, a rhombus and a parallelogram are separate shapes with th ```php interface Shape { - public function area(): int; + public function getArea(): int; } class Rectangle implements Shape @@ -1762,17 +1762,17 @@ class Rectangle implements Shape $this->height = $height; } - public function width(): int + public function getWdth(): int { return $this->width; } - public function height(): int + public function getHeight(): int { return $this->height; } - public function area(): int + public function getArea(): int { return $this->width * $this->height; } @@ -1787,12 +1787,12 @@ class Square implements Shape $this->length = $length; } - public function length(): int + public function getLength(): int { return $this->length; } - public function area(): int + public function getArea(): int {        return $this->length ** 2;    } @@ -1800,7 +1800,7 @@ class Square implements Shape function printArea(Shape $shape): void { - echo sprintf('%s has area %d.', get_class($shape), $shape->area()).PHP_EOL; + echo sprintf('%s has area %d.', get_class($shape), $shape->getArea()).PHP_EOL; } $shapes = [new Rectangle(4, 5), new Square(5)];