Mode command (Command) command to package the object, and decoupling the sender of the command to the recipient. Thread pool, the MVC framework uses a command mode, herein, the following class diagram, realized by matlab command mode.
Invoker.m (transmission command object Invoker: hold command object, the object request command execution request)
classdef Invoker < handle properties command end methods function setOrder(obj,command) obj.command = command; end function execute(obj) obj.command.execute(); end end end
Command.m (abstract command interface Command: Command interface method definition, the statement executed)
classdef Command < handle methods(Abstract) execute(obj); end end
ConcreteCommand.m (specific command object ConcreteCommand: hold specific recipient objects to complete specific specific command)
classdef ConcreteCommand < Command properties receiver end methods function obj = ConcreteCommand(receiver) obj.receiver = receiver; end function execute(obj) obj.receiver.execute(); end end end
Receiver.m (recipient of the object Receiver: receiver objects, real objects execute command)
classdef Receiver < handle methods function execute(~) disp("Receiver execute"); end end end
test.m
r = Receiver(); c = ConcreteCommand(r); i = Invoker(); i.setOrder(c); i.execute();
References: