-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmro.py
More file actions
66 lines (38 loc) · 1.15 KB
/
Copy pathmro.py
File metadata and controls
66 lines (38 loc) · 1.15 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
56
57
58
59
60
61
62
63
64
65
66
"""
POO - MRO - Method Resolution Order
Method Resolution Order (Resolução de Ordem de Métodos), é a ordem
de execução dos métodos (quem será executado primeiro).
Em Python, a gente pode conferir a ordem de execução dos métodos (MRO) de 3 formas:
- Via pripriedade da classe __mro__
- Via método mro()
- Via help
"""
class Animal:
def __init__(self, nome):
self.__nome = nome
def cumprimentar(self):
return f'Eu sou {self.__nome}'
class Aquatico(Animal):
def __init__(self, nome):
super().__init__(nome)
def nadar(self):
return f'{self._Animal__nome} está nadando.'
class Terrestre(Animal):
def __init__(self, nome):
super().__init__(nome)
def andar(self):
return f'{self._Animal__nome} está andando.'
def cumprimentar(self):
return f'Eu sou {self._Animal__nome} da terra!'
class Pinguim(Aquatico, Terrestre):
def __init__(self, nome):
super().__init__(nome)
# Testando
tux = Pinguim('Tux')
print(tux.cumprimentar())
"""
Pinguim(Aquatico, Terrestre)
Eu sou Tux do mar!
Pinguim(Terrestre, Aquatico)
Eu sou Tux da terra!
"""