I have the following code
internal abstract class Base
{
public DateTime Time;
public string Message;
public string Log;
public abstract void Invoke(string message);
}
internal class SubA : Base
{
public override void Invoke(string message)
{
Time = DateTime.Now;
// Do A
}
}
internal class SubB : Base
{
public override void Invoke(string message)
{
Time = DateTime.Now;
// Do B
}
}
I have these SubA and SubB classes which inherits from Base class, you can see that i have a code that repeating it self which is setting the Time, is there a way to move the setting of the time to the base class?
There a many possible solutions.
This depends on when you want to have this propertie set.
If you want it immediately you can do this in the constructor of your
Baseclass.