-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_AbstractBasesClasses.py
More file actions
55 lines (38 loc) · 1.24 KB
/
_AbstractBasesClasses.py
File metadata and controls
55 lines (38 loc) · 1.24 KB
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
51
52
53
54
55
# coding=utf-8
import abc # Abstract Base Classes
class AbstractTalker(object):
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def format(self, message):
return message
def say(self, message):
print self.format(message)
class LoudTalker(AbstractTalker):
def format(self, message):
return "%s!" % message
class Screamer(LoudTalker):
def format(self, message):
return super(Screamer, self).format(message).upper()
class ShoutFormatterMixin(object):
def format(self, message):
return "%s!" % message
class PublicAddressSystem(ShoutFormatterMixin, AbstractTalker):
def play_music(self, song):
super(PublicAddressSystem, self).say(song.tablature)
if __name__ == '__main__':
b = LoudTalker()
b.say('b talking')
print(b.__class__.__base__)
print(b.__class__.__base__.__base__)
c = Screamer()
c.say('c talking')
print(c.__class__.__base__)
print(c.__class__.__base__.__base__)
print(c.__class__.__base__.__base__.__base__)
f = PublicAddressSystem()
f.say('f1')
print(f.__class__.__base__)
print(f.__class__.__base__.__base__)
print(f.__class__.__base__.__base__.__base__)
d = ShoutFormatterMixin()
print(d.format('d'))