is it possibly in c# to have some sort of base class functionality which is manipulated slightly based on the class. For instance say i have the following code (which will quite obviously not compile it’s meant to only be for demonstrative purposes)
class BaseFunctionality
{
public virtual bool adminCall
public static string MethodName(int id, string parameter)
{
if (adminCall)
return dbcall.Execute();
else
return dbcall.ExecuteMe();
}
}
class Admin : BaseFunctionality
{
override bool adminCall = true;
}
class Front : BaseFunctionality
{
override bool adminCall = false;
}
Now what i would like to be able to do is;
string AdminCall = Admin.MethodName(1, "foo");
string FrontCall = Front.MethodName(2, "bar");
Is their any way to do something like this? I’m trying to do everything with static methods so i do not have to instantiate classes all the time, and have nice clean code which is only being manipulated in one place.
The idea behind this is so that there is minimal code repeating and makes things easier to expand on, so for instance another class could implement the BaseFunctionality later on.
Your desire to use static methods is getting in the way of using inheritance properly. The base class in your example knows how to implement the functionality of the two sub-classes. A cleaner way of coding this would be:
you can then create other static methods or use singletons to access these methods if you must have static access. e.g.: