Skip to content

Instantly share code, notes, and snippets.

@fabio-filho
Last active August 27, 2018 18:45
Show Gist options
  • Save fabio-filho/afb739fd864e501dbaf349b429e8364e to your computer and use it in GitHub Desktop.
Save fabio-filho/afb739fd864e501dbaf349b429e8364e to your computer and use it in GitHub Desktop.
SOLID - Open/Closed
class Calculator:
def __init__(self, a, b):
self._a = a
self._b = b
pass
def calculate(self, operation):
if operation == "sum":
return self._a + self._b
elif operation == "sub":
return self._a - self._b
elif operation == "mult":
return self._a * self._b
elif operation == "div":
return self._a / self._b
elif operation == "pow":
return self._a / self._b
elif operation == "rest":
return self._a % self._b
else:
raise ValueError("Operation not found")
def main(a, b, operation):
c = Calculator(a, b)
print(c.calculate(operation))
pass
main(5, 6, "sum")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment