Given an interface, that should be Init to Run. Initialisation code must be run.
Initialisation is two part: one that depend of the configuration, one that do not.
The configurable one must be calling the other one if he does not want to duplicate that code.
public interface IProcess
{
bool Init(out string error);
bool Init(ProcessConfiguration processConf, out string error);
bool Run(object message, out ErrorCode errorCode);
// ...
}
And it's correct implementation :
public class ProcessGood : IProcess
{
public bool Init(out string error){
// Important Code
return true;
}
public bool Init(ProcessConfiguration processConf, out string error){
Init(out erreur);
// things about processConf
return true;
}
My issue is due to the existence of 2 init method, the need for one to call the other as default behavior is not well followed.
Is there a way using Interface/ Virtual / etc to force one Init to call the other?
Example of one incorrect implementation:
public class ProcessBad : IProcess
{
public bool Init(out string error){
// Important Code
return true;
}
public bool Init(ProcessConfiguration processConf, out string error){
// Init(out erreur); // some one forgot to type this.
// things about processConf
return true;
}