-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlecture_2.py
More file actions
46 lines (35 loc) · 893 Bytes
/
lecture_2.py
File metadata and controls
46 lines (35 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from abc import ABC, abstractmethod
class SwitchAble(ABC):
@abstractmethod
def turn_on(self):
pass
@abstractmethod
def turn_off(self):
pass
class Switch:
def __init__(self,appliance):
self.appliance = appliance
def toggle(self,state):
if state == "on":
self.appliance.turn_on()
else:
self.appliance.turn_off()
class Light(SwitchAble):
def turn_on(self):
print("Light Turning On")
def turn_off(self):
print("Light Turning Off")
class Fan(SwitchAble):
def turn_on(self):
print("Fan Turning On")
def turn_off(self):
print("Fan Turning Off")
light = Light()
s = Switch(light)
s.toggle("on")
s.toggle("off")
fan = Fan()
s1 = Switch(fan)
s1.toggle("on")
s1.toggle("off")
# In this method Nobody is tightly coupled so we can create any number of class