Created
January 11, 2019 17:37
-
-
Save chiroptical/6e1128aab6e65d46ed09f1cdea4544d9 to your computer and use it in GitHub Desktop.
Example ABC
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
#!/usr/bin/env python | |
from abc import ABCMeta, abstractmethod | |
class StorageStrategy(metaclass=ABCMeta): | |
@abstractmethod | |
def printSomething(self, something): | |
pass | |
class MongoDBStorageStrategy(StorageStrategy): | |
def printSomething(self, something): | |
print(something) | |
class RunStorageStrategy(): | |
def __init__(self, strategy): | |
if strategy == "MongoDB": | |
self.cls = MongoDBStorageStrategy() | |
def runStrategy(self): | |
self.cls.printSomething("hello, world") | |
def main(): | |
strategy = RunStorageStrategy("MongoDB") | |
strategy.runStrategy() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment