My abstract class implements an interface but doesn't implement some of its methods. How do I make i
Posted
by Stefan Monov
on Stack Overflow
See other posts from Stack Overflow
or by Stefan Monov
Published on 2010-04-13T12:31:12Z
Indexed on
2010/04/13
12:32 UTC
Read the original article
Hit count: 346
interface ICanvasTool
{
void Motion(Point newLocation);
void Tick();
}
abstract class CanvasTool_BaseDraw : ICanvasTool
{
protected abstract void PaintAt(Point location);
public override void Motion(Point newLocation)
{
// implementation
}
}
class CanvasTool_Spray : CanvasTool_BaseDraw
{
protected abstract void PaintAt(Point location)
{
// implementation
}
public override void Tick()
{
// implementation
}
}
This doesn't compile. I could add an abstract method "Tick_Implementation" to CanvasTool_BaseDraw, then implement ICanvasTool.Tick
in CanvasTool_BaseDraw
with a one-liner that just calls Tick_Implementation. Is this the recommended workaround?
© Stack Overflow or respective owner