I have two console apps, Query and Update, that share some functionality. I wanted to have the two classes inherit from a common base class, but the problem is that, for a console app, I have to have a static Main function. What I currently have is the following:
namespace Utils
{
public class ConsoleBase
{
protected const int ERROR_EXIT_CODE = 1;
protected static void printWarning(string msg) {...}
public ConsoleBase(IEnumerable<string> args) { ... }
...
namespace Update
{
class Update : ConsoleBase
{
private static ConsoleBase _consoleBase;
public static void Main(string[] args) { ... }
...
namespace Query
{
class Query : ConsoleBase
{
private static ConsoleBase _consoleBase;
public static void Main(string[] args) { ... }
...
It seems like a design problem for me to both inherit from ConsoleBase as well as have an instance of it as a static variable within each derived class. The reason I'm doing this is so that:
- I can have
protected staticmethods defined inConsoleBasethat are accessible to otherstaticmethods in the derived classes. - I can pass along command-line arguments to the constructor for
ConsoleBase, do common stuff, and then access the arguments again in the derived classes viapublicproperties and methods on the instance ofConsoleBase.
So in the derived classes, I have a mixture of calls to methods/properties on the instance of ConsoleBase, e.g.
_consoleBase.UseDebugMode()
As well as calling inherited static methods and accessing inherited constants that are defined in ConsoleBase, e.g.
printWarning(CONST_MSG_IN_BASE_CLASS);
Can I clean this up somehow? Is it bad to both inherit from a class as well as keep an instance of that base class around for working with?