So, I refactored the legacy code base that I inherited, and in this process I found a static class that encapsulates the logic of launching third-party applications. Essentially it looks (short for brevity, to show only one application):
using System.IO;
using System.Configuration;
public static class ExternalApplications
{
public string App1Path
{
get
{
if(null == thisApp1Path)
thisApp1Path = Configuration.AppSettings.Get("App1Path");
return thisApp1Path;
}
}
private string thisApp1Path = null;
public bool App1Exists()
{
if(string.IsNullOrEmpty(App1Path))
throw new ConfigurationException("App1Path not specified.");
return File.Exists(App1Path);
}
public void ExecuteApp1(string args)
{
}
}
A good attempt to separate external applications from the rest of the code, but it seems to me that this could be reorganized further. What I mean is something like this:
using System.IO;
public abstract class ExternalApplicationBase
{
protected ExternalApplicationBase()
{
InitializeFromConfiguration();
}
public string Path { get; protected set; }
public bool Exists()
{
if(string.IsNullOrEmpty(this.Path))
throw new ConfigurationException("Path not specified.");
return File.Exists(this.Path);
}
public virtual void Execute(string args)
{
}
protected abstract InitializeFromConfiguration();
}
public class App1 : ExternalApplicationBase
{
protected virtual void InitializeFromConfiguration()
{
}
}
public class App2 : ExternalApplicationBase
{
protected virtual void InitializeFromConfiguration()
{
}
}
My problems are as follows:
There may be a class, interface, or other construct that does this, and I just haven't stumbled upon it.
, . , , , ( ).
. ( , , , , , ).
, ( ) App.Config , ; , , ( ).
, , . , , .
P.S. , , , ; , . , , , , , , . !