From 5eb60e907564ba5fc3a23819218f0d4fe0ac43b7 Mon Sep 17 00:00:00 2001 From: davhojt Date: Thu, 19 Jan 2023 13:19:07 +0000 Subject: [PATCH] docs(person): explain constructor declaration --- subjects/mobile-dev/person/README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/subjects/mobile-dev/person/README.md b/subjects/mobile-dev/person/README.md index 8306911a7..ca2e24929 100644 --- a/subjects/mobile-dev/person/README.md +++ b/subjects/mobile-dev/person/README.md @@ -30,8 +30,9 @@ Here is an example of a class in Dart. `Point` is the name of the class, while ` ```dart class Point { - double x = 0; // attribute initialized to 0 - double y = 0; // attribute initialized to 0 + // Attributes initialized to 0. + double x = 0; + double y = 0; } ``` @@ -39,13 +40,13 @@ What if you want to initiate a `Point` with different `x` and `y`? We use constr ```dart class Point { - // Attributes + // Attributes initialized to 0. double x = 0; double y = 0; // Constructor Point(double x, double y) { - // Initializing attributes + // Sets the attributes to the value of the constructor arguments. this.y = y; this.x = x; } @@ -56,6 +57,8 @@ In Dart we can also use **constructor declaration** to save a few lines of code. ```dart class Point { + // The constructor initializes the attributes. + // Attributes do not need to be initialized as soon as the are declared. double x; double y;