Exforsys

Online Training

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 ...


Go Back   Exforsys > Testing > Software Patterns

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-30-2003, 12:56 PM
Tobin Harris
Guest
 
Posts: n/a
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


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 06-30-2003, 04:13 PM
Mikkel Heisterberg
Guest
 
Posts: n/a
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
>
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-30-2003, 06:01 PM
Richard Wheeldon
Guest
 
Posts: n/a
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-02-2003, 10:27 AM
Tobin Harris
Guest
 
Posts: n/a
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



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 05:23 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.