(Parte 2) Log, LogFileMixin, LogPrintMixin e a união de tudo até aqui
This commit is contained in:
@@ -1,14 +1,27 @@
|
|||||||
# Abstração
|
# Abstração
|
||||||
|
# Herança - é um
|
||||||
class Log:
|
class Log:
|
||||||
def log(self, msg):
|
def _log(self, msg):
|
||||||
raise NotImplementedError('Implemente o método log')
|
raise NotImplementedError('Implemente o método log')
|
||||||
|
|
||||||
|
def log_error(self, msg):
|
||||||
|
return self._log(f'Error: {msg}')
|
||||||
|
|
||||||
|
def log_success(self, msg):
|
||||||
|
return self._log(f'Success: {msg}')
|
||||||
|
|
||||||
|
|
||||||
class LogFileMixin(Log):
|
class LogFileMixin(Log):
|
||||||
def log(self, msg):
|
def _log(self, msg):
|
||||||
print(msg)
|
print(msg)
|
||||||
|
|
||||||
|
|
||||||
|
class LogPrintMixin(Log):
|
||||||
|
def _log(self, msg):
|
||||||
|
print(f'{msg} ({self.__class__.__name__})')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
l = LogFileMixin()
|
l = LogPrintMixin()
|
||||||
l.log('qualquer coisa')
|
l.log_error('qualquer coisa')
|
||||||
|
l.log_success('Que legal')
|
||||||
|
|||||||
Reference in New Issue
Block a user