Created
January 20, 2021 15:41
-
-
Save afrinjamanbd/3043017db70e420a08ad5ab19f82cdce to your computer and use it in GitHub Desktop.
A builder design pattern or chaining in 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 Calculator: | |
total = 0 | |
def add(self, number): | |
self.total = self.total + number | |
return self | |
def remove(self, number): | |
self.total = self.total - number | |
return self | |
def calc(self): | |
return self.total | |
A = Calculator().add(12).remove(3).calc() | |
print(A) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment