views:

104

answers:

1

I am writing helper classes for a large project in PHP and I have written a class called Command. It is essentially an OOP wrapper around running system commands from PHP in a controlled way. It has methods like addOption() to add -a type options and addArgument() to add other arguments.

I will need to do a lot of scp'ing of files around so I will be using the Command class a lot. The calls to scp are very specific in that I need certain options used every time.

Does it make sense to extend this class and create a ScpCommand class? It seems to have an 'is a' relationship, but it is really just the same thing as the Command class with specific options every time. I don't really think I would need to override any methods with the exception of the constructor. I probably would add just class variables. It would really just be a convenience.

What makes the most sense here?

+2  A: 

If it is just configuration, why not consider a factory which returns a Command after doing your boiler-plate configuration for you?

function getScpCommand($???) 
{
    $Command = new Command();
    $Command->addOption(/* scp specific this */);
    $Command->addArgument(/* scp specific that */);
    /* etc */
    $Command->addOption(/* handle your getScpCommand parameters here */)

    return $Command;
}
Ken
I agree I think you could easily make a good argument for using Factory. Nice thought.
Chris Kloberdanz
Is it truly a factory if I'm not using subclasses? Does it really matter?
Chris Kloberdanz
I don't think it really matters - if it fits as a solution then use it. Don't get too hung up on pattern definitions.
Ken
I ended up extending the class anyways because I had an execute() method that needed to be overridden because of the nature of the scp call. =)
Chris Kloberdanz