From c04d42ae9b02ab981fa8c07c64ef6fa99d26e92f Mon Sep 17 00:00:00 2001 From: davhojt Date: Thu, 19 Jan 2023 13:42:18 +0000 Subject: [PATCH] docs(circle): explain constructor declaration --- subjects/mobile-dev/circle/README.md | 42 ++++++++++++++-------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/subjects/mobile-dev/circle/README.md b/subjects/mobile-dev/circle/README.md index e6671ad9b..5c0cb5a99 100644 --- a/subjects/mobile-dev/circle/README.md +++ b/subjects/mobile-dev/circle/README.md @@ -1,35 +1,35 @@ -# Circle +## Circle ### Instructions -Create a class named `Circle`. +Create a `class` named `Circle`. -Its attributes: +Attributes: -- x - `double` -- y - `double` -- radius - `double` -- getters: +- `x`: `double` +- `y`: `double` +- `radius`: `double` - - area - - perimeter - - rightMostCoordinate (x axis) - - leftMostCoordinate (x axis) - - highestCoordinate (y axis) - - lowestCoordinate (y axis) +Getters: +- `area` +- `perimeter` +- `rightMostCoordinate`: (x axis) +- `leftMostCoordinate`: (x axis) +- `highestCoordinate`: (y axis) +- `lowestCoordinate`: (y axis) -- Constructor: - - x - `required` - - y - `required` - - radius - `required` +Constructor: +- `x`: `required` +- `y`: `required` +- `radius`: `required` ### Getters and setters -To work with objects, either getting some information or changing it, we should use methods as it might not be a good idea to directly change objects fields. +Getters and setters avoid directly accessing or modifying attributes from outside of the class. They provide an opportunity to perform validation when setting attributes, or programmatically calculate values when getting attributes. -An example of this principle is hunger - you should not change person's hunger level directly, but feed them instead. Since it is common to set or get these values, we use getters and setters in OOP. +Consider a `Vehicle` that has `batteryVoltage` attribute. It is better that the `lowBattery` attribute is calculated based on the `batteryVoltage`, instead of being set directly. -In Dart, when you specify getters and setters, you must treat them as **fields**. +In Dart, when you specify getters and setters, you must treat them as attributes. Syntax of the getters and setters: @@ -60,4 +60,4 @@ void main() { } ``` -- Note: Do not use math library, pi = 3.14 +> Do not use math library, pi = 3.14