Last active
August 27, 2018 18:45
-
-
Save fabio-filho/d72d41b17dde37730bf75a5e1768069c to your computer and use it in GitHub Desktop.
SOLID - Single responsability
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
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") |
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 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