Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created January 7, 2019 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/c90bc32e3ae665bcc0d1985e1b5d2bb4 to your computer and use it in GitHub Desktop.
Save Fhernd/c90bc32e3ae665bcc0d1985e1b5d2bb4 to your computer and use it in GitHub Desktop.
Delegar el acceso a un atributo a una clase. Python.
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