I've run into an issue in the past where I want two methods in an abstract class that, once implemented, would wind up with the same method definition. Obviously, I can name the methods slightly differently, but this seems inelegant because they serve the same purpose. Is there a better way to handle this than renaming?
public class foo
{
public string spam { get; set;}
}
public abstract class absService<T> where T : foo
{
protected void Validate(foo obj)
{
if (obj == null) throw new Exception("null obj");
}
protected abstract void Validate(T obj);
public object DoTheThing(T obj)
{
Validate((foo)obj);
Validate(obj);
//do stuff here
}
}
public class fooService : absService<foo>
{
protected override void Validate(foo Obj)
{
if (Obj.spam == null) throw new Exception("No spam");
}
}