-
Notifications
You must be signed in to change notification settings - Fork 0
/
interfaces.py
50 lines (33 loc) · 872 Bytes
/
interfaces.py
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
47
48
49
50
# Python is dynamic typed and has no concept of interfaces
# Ducktyping = if sth quacks like a duck, swims like a duck => it's a duck
# HOWEVER, one can implement the concept of interfaces via the use of ABC (Abstract Base Class)
from abc import ABC, abstractmethod
class AbstractIDE(ABC):
@abstractmethod
def execute(self):
pass
class PyCharm(AbstractIDE):
def execute(self):
print('Spell Check')
print('Convention Check')
print('Compiling')
print('Running')
class SimpleIde(AbstractIDE):
def execute(self):
print('Compiling')
print('Running')
class Laptop:
def code(self, ide):
ide.execute()
# from interfaces import *
# p = PyCharm()
# s = SimpleIde()
# l = Laptop()
# l.code(p)
# Spell Check
# Convention Check
# Compiling
# Running
# l.code(s)
# Compiling
# Running