Skip to content

Commit 670c14c

Browse files
Update Lecture2.md
1 parent 0c11678 commit 670c14c

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

tutorials/Lecture2.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,53 @@ The DRY pattern stands for "**Don't Repeat Yourself**"; it is a fundamental prin
117117
- Readability: The code is easier to read and understand because there is less repetition.
118118
- Consistency: Reduces the risk of inconsistencies and errors that can occur when updating duplicated code in multiple places.
119119

120+
```python
121+
##### WET #####
122+
def on(self):
123+
# method overriding polymorphism of the parent class
124+
self.high()
125+
if self.__debug:
126+
print(f"LED connected to Pin {self.__pin} is high")
127+
128+
def off(self):
129+
# method overriding polymorphism of the parent class
130+
self.low()
131+
if self.__debug:
132+
print(f"LED connected to Pin {self.__pin} is low")
133+
134+
def toggle(self):
135+
# method overriding polymorphism of the parent class
136+
if self.value() == 0:
137+
self.high()
138+
if self.__debug:
139+
print(f"LED connected to Pin {self.__pin} is high")
140+
elif self.value() == 1:
141+
self.low()
142+
if self.__debug:
143+
print(f"LED connected to Pin {self.__pin} is low")
144+
145+
##### DRY #####
146+
def on(self):
147+
# method overriding polymorphism of the parent class
148+
self.high()
149+
if self.__debug:
150+
print(f"LED connected to Pin {self.__pin} is high")
151+
152+
def off(self):
153+
# method overriding polymorphism of the parent class
154+
self.low()
155+
if self.__debug:
156+
print(f"LED connected to Pin {self.__pin} is low")
157+
158+
def toggle(self):
159+
# method overriding polymorphism of the parent class
160+
if self.value() == 0:
161+
self.on()
162+
elif self.value() == 1:
163+
self.off()
164+
165+
```
166+
120167
## Overloading Polymorphism
121168

122169
**Polymorphism means “many forms.”**

0 commit comments

Comments
 (0)