Created
January 7, 2019 19:30
-
-
Save Fhernd/c90bc32e3ae665bcc0d1985e1b5d2bb4 to your computer and use it in GitHub Desktop.
Delegar el acceso a un atributo a una clase. Python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Calculadora: | |
def sumar(self, a, b): | |
return a + b | |
def restar(self, a, b): | |
return a - b | |
class CalculadoraCientifica: | |
def __init__(self): | |
self._calculadora = Calculadora() | |
def potencia(self, a, b): | |
return a ** b | |
def __getattr__(self, atributo): | |
return getattr(self._calculadora, atributo) | |
calc = CalculadoraCientifica() | |
print(calc.potencia(5, 2)) | |
print(calc.sumar(3, 2)) | |
print(calc.restar(3, 2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment