Skip to content

Commit 9308123

Browse files
Update Lecture2.md
1 parent 8515688 commit 9308123

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

tutorials/Lecture2.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222

2323
Polymorphism Overriding occurs when a Sub Class provides a new implementation for a method it inherits from its Super Class.
2424

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()`).
2626

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.
2828

2929
```python
3030
from machine import Pin
@@ -124,7 +124,7 @@ The DRY pattern stands for "**Don't Repeat Yourself**"; it is a fundamental prin
124124
```
125125

126126
## 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.
128128

129129
### Benefits of Encapsulation:
130130

@@ -141,15 +141,15 @@ while True:
141141
```
142142

143143
> [!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.
145145
146146
## Setters & Getters
147147

148148
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.
149149

150150
### State Attribute
151151

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`.
153153

154154
```python
155155
def __init__(self, pin, flashing=False, debug=False):
@@ -250,7 +250,7 @@ Class Led_Light inherits from Pin:
250250

251251
### Adhoc Method Overloading
252252

253-
Adhoc Method Overloading is a common approach to overloading in Python, demonstrated in the below implementations.
253+
Adhoc Method Overloading is a common approach to overloading in Python, demonstrated in the implementations below.
254254

255255
```python
256256
# Default parameters
@@ -296,4 +296,4 @@ class MyClass:
296296
obj = MyClass()
297297
obj.my_method(42) # Integer!
298298
obj.my_method("hi") # String!
299-
```
299+
```

0 commit comments

Comments
 (0)