JRG
JRG

Reputation: 210

Enforce all child classes to contain variables of only a certain type

Here are my classes:

   public abstract class Input
{

}

public class CreatePendingOrderInput : Input
{
    public string customerNo;
    public string callingCountry;
}

public class GetCustomerDetailsInput : Input
{
    public string customerName;
    public string customerAge;
}

I want to enforce that any class that is a child of Input only define variables of type string. Is this possible?

Upvotes: 0

Views: 49

Answers (1)

Zohar Peled
Zohar Peled

Reputation: 82474

No, that's impossible. The only thing that is enforced when deriving from a base class is that the derived class has everything the base class have, except for constructors and finalizers.

Upvotes: 2

Related Questions