Jinsong said:
I have a class which serve as a base class. I want to focuses all the
classes derived from it implement a interface. Make it a abstract
class is not a option since some XML serialization code need to
initialize the class. is it possible?
thanks
Hi Jinsong,
The definition of an abstract class is a class which provides a template for
other classes. It does not contain enough information to instantiate it,
as parts are to be implemented by deriving classes. If you are forcing
classes to implement an interface, then you are saying that where you are
deriving from is not complete, i.e. abstract.
It doesn't make sense to force an implementation i.e. define abstract
methods in a non-abstract class, because an instance of that class would
yield methods that are not implemented.
You can define methods as virtual, which means that they _can_ be overridden
by derived classes, but not necessarily:
public class MyBaseClass
{
public virtual void Foo ()
{
}
}
public class MyDerivedClass : MyBaseClass
{
public override void Foo ()
{
// Overridden Implementation.
}
}