Created
October 17, 2016 15:00
-
-
Save solebox/a38ed8081c06fa57bf0e3c490290a9e3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/python | |
class Cow(object): | |
""" | |
the cow needs to have 1 stomach with 4 | |
sections! | |
(but here we only have one for simplicity) | |
""" | |
def __init__(self,stomach): # <- here we injected out stomach dependency | |
#into the cow class | |
self.stomach = Stomach() | |
def fart(self): | |
self.stomach.make_noise(strength=3) | |
self.stomach.exhust_gas() | |
class Stomach(object): | |
""" | |
this is out dependency | |
""" | |
def __init__(self): | |
pass | |
def make_noise(self, strength): | |
print("frrrrp "*strength) | |
def exhust_gas(self): | |
print("releasing green fumes of stinky gas") | |
if __name__ == "__main__": | |
stomach = Stomach() | |
cow = Cow(stomach) # the dependency is passed in the main to the cow , the | |
#cow has no idea of how to implement a somach just the | |
#methods it uses |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment