Commandパターンは、リクエストをオブジェクトとしてカプセル化する— アクションをスタンドアロンオブジェクトに変え、すべての情報を含める。これにより、キューイング、ロギング、アンドゥ/リドゥ、およびリクエスト元とエグゼキューターの分離が可能になります。
Commandパターンが行うこと
COMMAND → encapsulate an action/request as an OBJECT (with its data and an execute method):
→ a command object knows WHAT to do and has the info to do it
→ the invoker triggers commands without knowing their details
→ decouples the object that INVOKES from the object that PERFORMS the action
→ "turn an action into an object" → store, pass, queue, log, undo it
例
{
() { . = doc; . = text; }
() { ..(.); }
() { ..(.); }
}
cmd = (doc, );
cmd.();
cmd.();
