From 10e95910ce17e0b2eeb934a5638fb63fac6c1b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Ot=C3=A1vio?= Date: Wed, 16 Nov 2022 10:21:22 -0300 Subject: [PATCH] =?UTF-8?q?super()=20e=20a=20sobreposi=C3=A7=C3=A3o=20de?= =?UTF-8?q?=20membros=20-=20Python=20Orientado=20a=20Objetos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 2 +- aula139.py | 64 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 aula139.py diff --git a/.vscode/settings.json b/.vscode/settings.json index ccd47b0..f44e96a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,5 @@ { - "window.zoomLevel": 1, + "window.zoomLevel": 2, "editor.fontSize": 26, "editor.hover.enabled": true, "workbench.startupEditor": "none", diff --git a/aula139.py b/aula139.py new file mode 100644 index 0000000..810def9 --- /dev/null +++ b/aula139.py @@ -0,0 +1,64 @@ +# super() e a sobreposição de membros - Python Orientado a Objetos +# Classe principal (Pessoa) +# -> super class, base class, parent class +# Classes filhas (Cliente) +# -> sub class, child class, derived class +# class MinhaString(str): +# def upper(self): +# print('CHAMOU UPPER') +# retorno = super(MinhaString, self).upper() +# print('DEPOIS DO UPPER') +# return retorno + + +# string = MinhaString('Luiz') +# print(string.upper()) + +class A(object): + atributo_a = 'valor a' + + def __init__(self, atributo): + self.atributo = atributo + + def metodo(self): + print('A') + + +class B(A): + atributo_b = 'valor b' + + def __init__(self, atributo, outra_coisa): + super().__init__(atributo) + self.outra_coisa = outra_coisa + + def metodo(self): + print('B') + + +class C(B): + atributo_c = 'valor c' + + def __init__(self, *args, **kwargs): + # print('EI, burlei o sistema.') + super().__init__(*args, **kwargs) + + def metodo(self): + # super().metodo() # B + # super(B, self).metodo() # A + # super(A, self).metodo() # object + A.metodo(self) + B.metodo(self) + print('C') + + +# print(C.mro()) +# print(B.mro()) +# print(A.mro()) +c = C('Atributo', 'Qualquer') +# print(c.atributo) +# print(c.outra_coisa) +c.metodo() +# print(c.atributo_a) +# print(c.atributo_b) +# print(c.atributo_c) +# c.metodo()