Skip to content

Commit 1e1728d

Browse files
Update Lecture3.md
1 parent 670c14c commit 1e1728d

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

tutorials/Lecture3.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ Setters and getters are special methods used in object-oriented programming to a
3939
- A setter is a method that sets (updates) the value of a private attribute.
4040
- It allows you to validate or restrict changes before updating the attribute.
4141

42+
```python
43+
@property
44+
def led_light_state(self):
45+
# method overloading polymorphism in this class
46+
return self.value()
47+
48+
@led_light_state.setter
49+
def led_light_state(self, value):
50+
# method overloading polymorphism in this class
51+
if value == 1:
52+
self.off()
53+
elif value == 0:
54+
self.on()
55+
```
56+
4257
### Why Use Setters & Getters
4358
- Encapsulation: Protects the internal state of the object.
4459
- Validation: Allows you to add checks before changing values.

0 commit comments

Comments
 (0)