I'm creating a reporting application that will create lots of different kinds of reports, so I'm implementing the Command pattern to encapsulate the function of actually creating the report.
I have the following classes:
- Report. The Command. Abstract base class, contains abstract Start() method.
- MyReport1Report. Inherits Report, implements Start() method to create the physical MyReport1 file.
- MyReport2Report. Inherits Report, implements Start() method to create the physical MyReport2 file.
- ReportHandler. The Invoker. Contains a Queue of reports to execute, and an Add(Report rpt) method to allow you to add reports to the queue to be executed.
The Main class gets the next concrete Report object to execute from a ReportList class, adds it to the ReportHandler, and calls execute via the ReportHandler. Internally the ReportHandler class also contains a method to handle what to do when a Report completes.
So I've completely, and probably incorrectly, by-passed the Receiver class from the Command pattern. Could someone point out why a Receiver class is needed in this example?
Question
$phinX
I'm creating a reporting application that will create lots of different kinds of reports, so I'm implementing the Command pattern to encapsulate the function of actually creating the report.
I have the following classes:
- Report. The Command. Abstract base class, contains abstract Start() method.
- MyReport1Report. Inherits Report, implements Start() method to create the physical MyReport1 file.
- MyReport2Report. Inherits Report, implements Start() method to create the physical MyReport2 file.
- ReportHandler. The Invoker. Contains a Queue of reports to execute, and an Add(Report rpt) method to allow you to add reports to the queue to be executed.
The Main class gets the next concrete Report object to execute from a ReportList class, adds it to the ReportHandler, and calls execute via the ReportHandler. Internally the ReportHandler class also contains a method to handle what to do when a Report completes.
So I've completely, and probably incorrectly, by-passed the Receiver class from the Command pattern. Could someone point out why a Receiver class is needed in this example?
Link to comment
Share on other sites
8 answers to this question
Recommended Posts