Last active
March 12, 2023 14:21
-
-
Save bgoetzmann/4b7c3bf851b15310148c67815b2b9905 to your computer and use it in GitHub Desktop.
Used in this article: https://medium.com/@bgoetzmann/modèle-de-conception-commande-en-langage-groovy-9bea26b47d6
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
class MacroCartCommand implements CartCommand { | |
def commands = [] | |
MacroCartCommand leftShift(CartCommand command) { | |
commands << command | |
this | |
} | |
void setReceiver(Cart cart) { | |
commands*.cart = cart | |
} | |
def execute() { | |
commands*.execute() | |
} | |
} | |
def macroCommand = new MacroCartCommand() | |
macroCommand << command1 << command2 << command3 | |
def newCart = new Cart() | |
macroCommand.receiver = newCart | |
macroCommand.execute() | |
assert newCart.items.keySet() == ['Item2'] as Set |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment