Skip to content

Instantly share code, notes, and snippets.

@fabio-filho
Last active August 27, 2018 18:45
Show Gist options
  • Save fabio-filho/d72d41b17dde37730bf75a5e1768069c to your computer and use it in GitHub Desktop.
Save fabio-filho/d72d41b17dde37730bf75a5e1768069c to your computer and use it in GitHub Desktop.
SOLID - Single responsability
def main(a, b, operation):
result = None
if operation == "sum":
result = a + b
elif operation == "sub":
result = a - b
elif operation == "mult":
result = a * b
elif operation == "div":
result = a / b
a = ""
print(result)
pass
main(5, 6, "sum")
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
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