I have to implement a few action. Each of they have some common elements, so they should inherit from one class. Lets say, that they are do some web actions, so base class is
public class WebAction
{
private ServerData _serverData;
public WebAction(ServerData serverData)
{
_serverData = serverData;
}
}
Also, each of this action need to be execute, so in base class I also should have some sort of Execute() Method. Problem is, that each of this object do a little bit different thing, so It should take different parameters. My question is – witch way is best for reach this?
At first I was thinking abut some configuration object, e,g. Execute(IWebActionConfig config). In this case, I can use object like:
LoginWebAction loginWebAction = LoginWebAction(staticServerConfig);
LoginWebActionConfig = new LoginWebActionConfig { someData = "foo" };
loginWebAction.Execute(loginWebActionConfig);
But is there any sense to create an additional tree of objects? Maybe will be better to configure each child of WebAction by properties?
LoginWebAction loginWebAction = LoginWebAction(staticServerConfig);
loginWebAction.someData = "foo";
// Execute will throw exception when someData not set
loginWebAction.Execute();
With of these (if any) way is better?
It is possible to do in more OOP style. look at NVI pattern