Is it possible to create a base class like the following:
public abstract class baseClass
{
public abstract void SetParameters(/*want this to be adjustable*/);
}
so that classes that override it can define the parameters required? In other words, I want to force the method to be overridden, but leave it up to the overriding class what is required here - so one might be
public class derivedClass1 : baseClass
{
public override void SetParameters(Point a, int b);
}
whereas another could be
public class derivedClass2 : baseClass
{
public override void SetParameters(List<Line> a, Point b, Point c, bool e);
}
?
Thanks for any help you can give
Absolutely not - that would break half the point of having the abstract method in the first place - no-one would be able to call it, because they wouldn't know which method signature had actually been written. The whole point of an abstract class is that a client can have a reference of type BaseClass
without caring about what the type of the actual implementation is.
If the base class is able to predict in advance which types might be involved, one possibility to make life easier for the caller is to have the most general signature (typically the one with the most parameters) abstract, and make various overloads which call that general one providing defaults for the parameters that the client hasn't specified.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With