Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have to run certain number of statements (which are executing .exe) in a loop.

 ForEach(object obj in ListOfVersions)
    {
      Step 1: call Exe1 Args=obj.somevalues
      Log Step 1 completed for obj

      Step 2: call Exe2 Args=obj.somevalues
      Log Step 2 completed for obj

      Step 3: call Exe3 Args=obj.somevalues
      Log step 3 completed for obj
    }

Step 4: call Exe4

Is there any specific design pattern available to use for above situation.

share|improve this question
    
Why are you doing this? is this not what ms dos ".bat" where scripts created for? –  Darknight May 2 '12 at 15:19
add comment

3 Answers

There is no specific pattern in the general sense. If you're referring to asynchronous operations, then the below answer is not what you're looking for:

public void executeForAll() 
{
    ForEach(object obj in ListOfVersions)
    {
      execute("Exe1", obj);
      execute("Exe2", obj);
      execute("Exe3", obj);
    }
    execute("Exe4");
}

public void execute(String executable) 
{
    execute(executable, null);
}

public void execute(String executable, object obj) 
{
    // Call executable Args=obj == null ? null : obj.somevalues
    log(executable, obj);
}

public void log(String executable, object obj)
{
    // Log Step 2 completed for obj
}
share|improve this answer
add comment

I agree with @Neil saying that there looks to be no special pattern name for this processing type. The name I would give for it is "Batch Processing Job" with each call representing a step in the batch. This naming is frequently used in some ETL Tools and Mainframes.

Notice the following though:

  • You need to decide whether you keep all the logs in one file or not. If you intend to, you have two options, either to use separate files and concatenate at end of all processes or to use one stream writer and keep it open until all processes finish then flush it and close in all cases (even when one process fails).

  • You need to do error checking after each call.

share|improve this answer
add comment

Depending upon how everthing is implemented, this might be an example of the Observer Pattern.

But design patterns aren't themselves solutions, they are something which allows you to better design, implement and communicate about your solution once you have recognized that it is ALREADY the pattern. Given the limited context, you don't have a design pattern, you an inner loop (depending upon the details of your excel args and logging, for example it's reasonable to assume that all of your logging goes to the same log, but it might not, and you might be logging different details).

A particular design pattern is a short description referring to the structure of your solution, it doesn't help you arrive at the solution (except in the special case of a student told to do x using pattern y).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.