class must only be used as a base class

S

Steve Richter

I have a class, "BaseUserTable", that must be derived from to be used
correctly:

class BaseUserTable
{
public virtual string TableName
{
get { throw( new ApplicationException( "where's the TableName
property in the derived class??" )) ; }
}
}

( the idea is that BaseUserTable contains methods for managing the
UserTable, only an application that uses the class must supply the
actual table name and database connection string. )

How do I do this in c#/.net? I want derived classes to get a compile
error if they dont implement the required virtual methods and
properties.

I am curious if an interface can do the trick. I just dont want to have
to implement the interface in this base class.

thanks,

-Steve
 
L

Lebesgue

You may want to make the base class abstract (methods that have to be
overriden as well)

abstract class Foo
{
public abstract void Do();
}

class Bar : Foo
{
public override void Do()
{
//do foo
}
}
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Just declare the base class as abstract. Another way to avoid the creation
of a class is declaring the constructor as private , in this way you cannot
create an instance of it.


cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top