Skip to content

Instantly share code, notes, and snippets.

@housemeow
Created February 26, 2018 06:53
Show Gist options
  • Save housemeow/918b260024d90be1a032885f786299ba to your computer and use it in GitHub Desktop.
Save housemeow/918b260024d90be1a032885f786299ba to your computer and use it in GitHub Desktop.
class Command:
def redo(self, **kwargs):
abstract
def undo(self, **kwargs);
abstract
class UploadImgurCommand extend Command:
def redo(self, **kwargs):
image = kwargs['image'];
try:
return imgurApi.upload(image);
catch Exception as ex:
throw ex;
def undo(self, **kwargs):
whatever
class InsertToMangoCommand extend Command:
def redo(self, **kwargs):
image_url = kwargs['image_url']
try:
return mongoApi.insert(image_url);
catch Exception as ex:
throw ex;
class YourApplication:
def upload_image(self, image):
command_classes = [UploadImgurCommand, InsertToMangoCommand];
args = { image: image }
command_index = 1
for command_class in command_classes:
command = command_class(args);
try:
args = command.redo(args)
catch Exception as ex:
whatever
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment