(Parte 4) Eletrônico, Smartphone com Mixin e a união de tudo até aqui
This commit is contained in:
31
aula141/eletronico.py
Normal file
31
aula141/eletronico.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
from log import LogFileMixin
|
||||||
|
|
||||||
|
|
||||||
|
class Eletronico:
|
||||||
|
def __init__(self, nome):
|
||||||
|
self._nome = nome
|
||||||
|
self._ligado = False
|
||||||
|
|
||||||
|
def ligar(self):
|
||||||
|
if not self._ligado:
|
||||||
|
self._ligado = True
|
||||||
|
|
||||||
|
def desligar(self):
|
||||||
|
if self._ligado:
|
||||||
|
self._ligado = False
|
||||||
|
|
||||||
|
|
||||||
|
class Smartphone(Eletronico, LogFileMixin):
|
||||||
|
def ligar(self):
|
||||||
|
super().ligar()
|
||||||
|
|
||||||
|
if self._ligado:
|
||||||
|
msg = f'{self._nome} está ligado'
|
||||||
|
self.log_success(msg)
|
||||||
|
|
||||||
|
def desligar(self):
|
||||||
|
super().desligar()
|
||||||
|
|
||||||
|
if not self._ligado:
|
||||||
|
msg = f'{self._nome} está desligado'
|
||||||
|
self.log_error(msg)
|
||||||
@@ -5,3 +5,7 @@ Error: qualquer coisa (LogFileMixin)
|
|||||||
Success: Que legal (LogFileMixin)
|
Success: Que legal (LogFileMixin)
|
||||||
Error: qualquer coisa (LogFileMixin)
|
Error: qualquer coisa (LogFileMixin)
|
||||||
Success: Que legal (LogFileMixin)
|
Success: Que legal (LogFileMixin)
|
||||||
|
Success: Galaxy S está ligado (Smartphone)
|
||||||
|
Error: iPhone está desligado (Smartphone)
|
||||||
|
Success: Galaxy S está ligado (Smartphone)
|
||||||
|
Error: iPhone está desligado (Smartphone)
|
||||||
|
|||||||
@@ -1 +1,7 @@
|
|||||||
from log import LogFileMixin, LogPrintMixin
|
from eletronico import Smartphone
|
||||||
|
|
||||||
|
galaxy_s = Smartphone('Galaxy S')
|
||||||
|
iphone = Smartphone('iPhone')
|
||||||
|
|
||||||
|
galaxy_s.ligar()
|
||||||
|
iphone.desligar()
|
||||||
|
|||||||
Reference in New Issue
Block a user