Download Making Embedded Systems

Transcript
Command line input
Array
of
Commands
Determine which
command to run
then execute
Get parameters
run receiver
Does action
Invoker
Command
Receiver
Figure 3-14. How the command handler work
Client
Maps the receivers onto commands. Clients create concrete command objects and
create the association between receivers and command objects. A client may run
at initialization (as it was done in our example by creating an array) or create the
associations on the fly.
Invoker
Determines when the command needs to run and executes it. It doesn't know anything about the receiver. It treats every command the same.
Command object
An interface for executing an operation. This is a C++ class, a Java interface, or a
C structure with a function pointer. An instantiation of the command interface is
called a concrete command.
Receiver
Knows how to service the request. This is goal code to be run.
Figure 3-15 shows the purpose of each element of the command pattern.
68 | Chapter 3: Getting the Code Working