From de32cbd6b1fab5e2f62ce48a0cab0a41e003fa0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Ot=C3=A1vio?= Date: Thu, 17 Nov 2022 11:42:07 -0300 Subject: [PATCH] =?UTF-8?q?(Parte=204)=20Eletr=C3=B4nico,=20Smartphone=20c?= =?UTF-8?q?om=20Mixin=20e=20a=20uni=C3=A3o=20de=20tudo=20at=C3=A9=20aqui?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aula141/eletronico.py | 31 +++++++++++++++++++++++++++++++ aula141/log.txt | 4 ++++ aula141/main.py | 8 +++++++- 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 aula141/eletronico.py diff --git a/aula141/eletronico.py b/aula141/eletronico.py new file mode 100644 index 0000000..dd22de7 --- /dev/null +++ b/aula141/eletronico.py @@ -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) diff --git a/aula141/log.txt b/aula141/log.txt index f7144c9..8a1bf95 100644 --- a/aula141/log.txt +++ b/aula141/log.txt @@ -5,3 +5,7 @@ Error: qualquer coisa (LogFileMixin) Success: Que legal (LogFileMixin) Error: qualquer coisa (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) diff --git a/aula141/main.py b/aula141/main.py index 07ffe2d..35e993a 100644 --- a/aula141/main.py +++ b/aula141/main.py @@ -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()