I"m not entirely sure I follow.. but I'll give it a shot.
Basicall you want all derived classes to implement certain properties
and / or methods? To do this, you can have a base class (if you have
some functionality which you are SURE will be common to all derived
classes) or an interface.
If you go the base class route, make your base class abstract, and make
nay property or method which must be implemented by subclasses as
abstract as well.
for example:
public abstract MyBase {
public abstract string TableName { get; }
}
Anyone that derives MyBase MUST provide a property called TableName,
which is get only. (Note this is differnt than virtual, wher you
provide implementation, but the subcase MAY override the behavior).
If you go the interface route, you'd have something similar:
public interface IMyInterface {
public string TableName { get; }
}
use the interface if you need to have some behavior applied to classes
which are otherwise unrelated. For example, Float and DateTime
implement the IComparable interface, meaning they can be compared, but
don't share anything else in common.
HTH
Andy
cody wrote:
I have a base class and I want that all derived classes must have
attributes which contains entity specific stuff like a table name and a
userfriendly class name.
For specific reasons I want these things to be accessible also without
an instance of that class.
Sure, I could implement static variables and properties in each derived
class. But How could I ensure that the people deriving from my class are
doing so and most importantly, do the signatures correctly.
So if I would use reflection to retrieve the tablename of a given class
and I look for a property named TableName but the programmer of that
class unintentionally named the property NameOfTable (or whatever).
Since these informations are per class I have to make them static so
interfaces are not of use here.