Here’s what I have right now:
public abstract class SampleClass
{
public abstract void ShowAll();
public abstract void ExecuteById(int id);
public string sampleString{get;}
}
public sealed class FirstClass : SampleClass
{
public override string sampleString
{
get { return "AA"; }
}
public override void ShowAll()
{
......
}
public override void ExecuteById(int id)
{
......
}
}
public sealed class SecondClass : SampleClass
{
public override string sampleString
{
get { return "BB"; }
}
public override void ShowAll()
{
......
}
public override void ExecuteById(int id)
{
......
}
}
Now I add a function like this to each of the classes
public void runStoredProcedure(string sampleString)
{
SQLClass.ExecuteStoredProcedure(sampleString)
}
One of the ways of doing that is to just add this as an abstract to sampleClass and as an ovverride to FirstClass and SecondClass. Altough the only difference is the passing parameter (samplestring).
The question: is it possible to place this function somewhere(probably in SampleClass) and pass overriden string to this function from First/Second classes to avoid overhead?
Yes. What you usually want to do is declare the things that children must define as abstract (so the inheriting classes have to override them). Properties can be abstract too:
then you can do: