For studying purpose, I am trying to migrate this Java Command Pattern example to PHP:
https://codereview.stackexchange.com/questions/52110/command-pattern-implementation
As @simon commented, using method reference operator, would modernize quite a bit the code:
class MyCommand implements Order {
private final Runnable action;
public MyCommand(Runnable action) {
this.action = action;
}
@Override
public void execute() {
action.run();
}
}
And then you could create commands like this:
MyCommand bsc = new MyCommand(stock::buy);
MyCommand ssc = new MyCommand(stock::sell);
My current PHP implementation is here: https://3v4l.org/iIHn9
So what is the best approach to implement the MyCommand Class in PHP?
