generated from grellert/ine5404-aula-03-nov-solid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5.dip.py
41 lines (27 loc) · 796 Bytes
/
5.dip.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
"""
Dependency Inversion Principle
Dependências devem ser feitas sobre abstrações, não sobre implementações concretas
"""
from abc import ABC, abstractclassmethod
class Report(ABC):
def __init__(self, char) -> None:
self.char = char
@abstractclassmethod
def report(self):
pass
class Player:
def __init__(self, name, reporter: Report):
self.__reporter = reporter
self.__name = name
self.__hp = 100
self.__speed = 1
def hp(self):
return self.__hp
def name(self):
return self.__name
class StatsReporter(Report):
def __init__(self, char: Player) -> None:
super().__init__(char)
def report(self):
print(f'Name:{self.char.name()}')
print(f'HP:{self.char.hp()}')