Pattern 3Replacing Command

Intent

To turn a method invocation into an object and execute it in a central location so that we can keep track of invocations so they can be undone, logged, and so forth

Overview

Command encapsulates an action along with the information needed to perform it. Though it seems simple, the pattern has quite a few moving parts. In addition to the Command interface and its implementations, there’s a client, which is responsible for creating the Command; an invoker, which is responsible for running it; and a receiver, on which the Command performs its action.

The invoker is worth talking about a little because it’s often misunderstood. It helps to decouple the invocation of a method from the client asking for it to be ...

Get Functional Programming Patterns in Scala and Clojure now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.