You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tutorials/Lecture2.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,9 +22,9 @@
22
22
23
23
Polymorphism Overriding occurs when a Sub Class provides a new implementation for a method it inherits from its Super Class.
24
24
25
-
The method in the Sub Class has the same name and parameters as the one in the Super Class. When the method is called on an object of the Sub Class, Python (or any object-oriented language) uses the Sub’s version, even if the object is referenced using the Super type (`self.super.method()`).
25
+
The method in the Sub Class has the same name and parameters as the one in the Super Class. When the method is called on an object of the Sub Class, Python (or any object-oriented language) uses the Sub Class’s version, even if the object is referenced using the Super type (`self.super.method()`).
26
26
27
-
In this example we will apply overriding polymorphism and develop new implementations for the `on()`, `off()` and `toggle()` methods. We will extend the functionality of the methods to provide debugging support.
27
+
In this example, we will apply overriding polymorphism and develop new implementations for the `on()`, `off()` and `toggle()` methods. We will extend the functionality of the methods to provide debugging support.
28
28
29
29
```python
30
30
from machine import Pin
@@ -124,7 +124,7 @@ The DRY pattern stands for "**Don't Repeat Yourself**"; it is a fundamental prin
124
124
```
125
125
126
126
## Encapsulation
127
-
Encapsulation restricts direct access to some of an object's components (such as attributes or methods), meaning the internal representation of the object is hidden from the outside. This is typically achieved by making certain attributes or methods private (i.e., inaccessible from outside the ) and providing public methods (such as getters and setters) to access or modify those private members.
127
+
Encapsulation restricts direct access to some of an object's components (such as attributes or methods), meaning the internal representation of the object is hidden from the outside. This is typically achieved by making certain attributes or methods private (i.e., inaccessible from outside the class), and providing public methods (such as getters and setters) to access or modify those private members.
128
128
129
129
### Benefits of Encapsulation:
130
130
@@ -141,15 +141,15 @@ while True:
141
141
```
142
142
143
143
> [!Note]
144
-
> In Python, identifiers (variable or method names) that start with double underscores (e.g., `__my_var`) are not truly private in the sense of other languages like C# or C++. Instead, Python uses a mechanism called name mangling. When you define a variable with double underscores, Python changes its name internally to `_ClassName__my_var`. This means it is harder (but not impossible) to access it from outside the .
144
+
> In Python, identifiers (variable or method names) that start with double underscores (e.g., `__my_var`) are not truly private in the sense of other languages like C# or C++. Instead, Python uses a mechanism called name mangling. When you define a variable with double underscores, Python changes its name internally to `_ClassName__my_var`. This means it is harder (but not impossible) to access it from outside the class.
145
145
146
146
## Setters & Getters
147
147
148
148
Setters and getters are special methods used in object-oriented programming to access (get) or modify (set) the values of private or protected attributes of a class. They help encapsulate the internal state of an object, providing controlled access.
149
149
150
150
### State Attribute
151
151
152
-
First we need an attribute to hold state for the setter and getter `self.led_light_state`.
152
+
First, we need an attribute to hold state for the setter and getter `self.led_light_state`.
0 commit comments