I cannot decide which approach I have to choose. Could you give me some tips to make an educated decision?
With abstract
abstract class Shape
{
protected abstract void SpecificJob();
public void Print()
{
//other common code goes here
SpecificJob();
//other remaining common code goes here
}
}
sealed class Circle : Shape
{
protected override void SpecificJob()
{
//specific code goes here
}
}
With delegate
abstract class Shape
{
public void Print(Action specificJob)
{
//other common code goes here
specificJob?.Invoke();
//other remaining common code goes here
}
}
sealed class Circle : Shape
{
}
Aucun commentaire:
Enregistrer un commentaire