Skip to content

Instantly share code, notes, and snippets.

@chiroptical
Created January 11, 2019 17:37
Show Gist options
  • Save chiroptical/6e1128aab6e65d46ed09f1cdea4544d9 to your computer and use it in GitHub Desktop.
Save chiroptical/6e1128aab6e65d46ed09f1cdea4544d9 to your computer and use it in GitHub Desktop.
Example ABC
#!/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