Conceptual output of the Command pattern
mainThe Command pattern implementation demonstrates the interaction between an Invoker, SimpleCommand, ComplexCommand, and a Receiver.
- The
Invokertriggers the execution and manages the lifecycle (before and after execution). SimpleCommandhandles basic, direct actions (e.g., printing).ComplexCommanddelegates heavy lifting to aReceiverobject.- The
Receivercontains the actual business logic for complex tasks like sending emails or saving reports.
Invoker: Does anybody want something done before I begin?
SimpleCommand: See, I can do simple things like printing (Say Hi!)
Invoker: ...doing something really important...
Invoker: Does anybody want something done after I finish?
ComplexCommand: Complex stuff should be done by a receiver object.
Receiver: Working on (Send email.)
Receiver: Also working on (Save report.)