
- Forum
- Testing
- Software Patterns
- Command Pattern Issues
Command Pattern Issues
This is a discussion on Command Pattern Issues within the Software Patterns forums, part of the Testing category; Hi there, I want to be able to chain up steps in a process into various configurations. One approach I ...
-
06-30-2003, 12:56 PM #1Tobin Harris Guest
Command Pattern Issues
Hi there,
I want to be able to chain up steps in a process into various
configurations. One approach I considered was the command pattern, where I
see this as a variation on the 'Macro' theme. An example of one such 'macro'
or process configuration is :
fileName = "c:\temp.txt";
CompositeCommand c = new CompositeCommand();
c.AddCommand( new ExtractFileData( fileName, "output.dat" ) );
c.AddCommand( new FtpFile( ftpSettings, fileName )
c.AddCommand( new ZipUpFile( fileName, fileName + ".zip" ) );
c.AddCommand( new MoveFile( fileName + ".zip", "c:\backup\" + ) );
c.Run();
Another configuration might include some steps, exclude others etc.
Anyone ever done this kinda thing? My main consideration is that I don't
have any flow control, for example, for aborting the macro on failure etc?
Perhaps the commands interface be something like the following so I can test
for success before going to the next step?
interface Command{
void Run();
bool Succeeded();
}
Any thoughts or experiences on this would be apprecitaed before I get
carried away down a fruitless route!?
Tobes
-
06-30-2003, 04:13 PM #2Mikkel Heisterberg Guest
Re: Command Pattern Issues
I have used a similar approach to implement a very similar scenario
(text editing using a particular third party API). In my approach the
"run" method throws an exception on failure, and since all must complete
or none I can abort if an exception is caught.
Your example looks to be similar.
I have had a lot of benefit from structuring the code using the Command
pattern on a number of occasions.
lekkim
Tobin Harris wrote:
> Hi there,
>
> I want to be able to chain up steps in a process into various
> configurations. One approach I considered was the command pattern, where I
> see this as a variation on the 'Macro' theme. An example of one such 'macro'
> or process configuration is :
>
> fileName = "c:\temp.txt";
> CompositeCommand c = new CompositeCommand();
> c.AddCommand( new ExtractFileData( fileName, "output.dat" ) );
> c.AddCommand( new FtpFile( ftpSettings, fileName )
> c.AddCommand( new ZipUpFile( fileName, fileName + ".zip" ) );
> c.AddCommand( new MoveFile( fileName + ".zip", "c:\backup\" + ) );
> c.Run();
>
> Another configuration might include some steps, exclude others etc.
>
> Anyone ever done this kinda thing? My main consideration is that I don't
> have any flow control, for example, for aborting the macro on failure etc?
> Perhaps the commands interface be something like the following so I can test
> for success before going to the next step?
>
> interface Command{
> void Run();
> bool Succeeded();
> }
>
> Any thoughts or experiences on this would be apprecitaed before I get
> carried away down a fruitless route!?
>
> Tobes
>
>
-
06-30-2003, 06:01 PM #3Richard Wheeldon Guest
Re: Command Pattern Issues
Tobin Harris wrote:
> I want to be able to chain up steps in a process into various
> configurations. One approach I considered was the command pattern, where I
> see this as a variation on the 'Macro' theme. An example of one such 'macro'
> or process configuration is :
>
> fileName = "c:\temp.txt";
> CompositeCommand c = new CompositeCommand();
> c.AddCommand( new ExtractFileData( fileName, "output.dat" ) );
> c.AddCommand( new FtpFile( ftpSettings, fileName )
> c.AddCommand( new ZipUpFile( fileName, fileName + ".zip" ) );
> c.AddCommand( new MoveFile( fileName + ".zip", "c:\backup\" + ) );
> c.Run();
....
> Any thoughts or experiences on this would be apprecitaed before I get
> carried away down a fruitless route!?
Not really a pattern advice, but have you considered writing the code
as a set of Ant tasks ? In the above example, that would mean you'd
probably have to write code for a ExtractFileData task (hopefully
using a better name!). The ftp, zip and move commands are already
written, you'd just have to write the xml to configure it.
Richard
-
07-02-2003, 10:27 AM #4Tobin Harris Guest
Re: Command Pattern Issues
"Richard Wheeldon" <richard@rswheeldon.com> wrote in message
news:3F00A524.2781@rswheeldon.com...
> Tobin Harris wrote:
> > Any thoughts or experiences on this would be apprecitaed before I get
> > carried away down a fruitless route!?
>
> Not really a pattern advice, but have you considered writing the code
> as a set of Ant tasks ? In the above example, that would mean you'd
> probably have to write code for a ExtractFileData task (hopefully
> using a better name!). The ftp, zip and move commands are already
> written, you'd just have to write the xml to configure it.
An interesting idea actually! For this project it probably wouldn't be
suitable, becuase it has a GUI and I need threading control etc (I'm sure it
could be done, but perhaps a little too much research). Something similar to
the ANT configuration file is a nice way of building 'Jobs' though.
Regards,
Tobin
> Richard
-
Sponsored Ads

Reply With Quote





