M
Magne Ryholt
I have a base class and a chain of derived classes.
The base and its derived classes are all abstract except the last in chain
(a concrete class).
I want to provide some functionalities in the base class by defining a
member as e.g. "protected virtual MyReturnClass MyMethod(){...}"
The base classes, including the last (concrete class) adds on this
functionality by defining members as e.g. "protected override MyReturnClass
MyMethod(){... return base.MyMethod();}"
This works fine, however I often forget to implement MyMethod in the classes
(both abstract and the concrete class(es), except (obviously) the "top
base").
Of course this is found during testing, but I would like the compiler to, at
least warn me that "my intention is not fulfilled" (better yet with an
error).
Abstract member declarations would enforce this, but abstract members cannot
contain any body, so I am looking for something like a special abstract
modifier which accepts code-bodies (I know this does not exist).
Is there a way to force overriding by combining some of the modifiers or by
other means (e.g. interfaces etc.) ?
What if the "chained functionalites" needs to be bodies of constructors (as
it is in my actual case) ?
The base and its derived classes are all abstract except the last in chain
(a concrete class).
I want to provide some functionalities in the base class by defining a
member as e.g. "protected virtual MyReturnClass MyMethod(){...}"
The base classes, including the last (concrete class) adds on this
functionality by defining members as e.g. "protected override MyReturnClass
MyMethod(){... return base.MyMethod();}"
This works fine, however I often forget to implement MyMethod in the classes
(both abstract and the concrete class(es), except (obviously) the "top
base").
Of course this is found during testing, but I would like the compiler to, at
least warn me that "my intention is not fulfilled" (better yet with an
error).
Abstract member declarations would enforce this, but abstract members cannot
contain any body, so I am looking for something like a special abstract
modifier which accepts code-bodies (I know this does not exist).
Is there a way to force overriding by combining some of the modifiers or by
other means (e.g. interfaces etc.) ?
What if the "chained functionalites" needs to be bodies of constructors (as
it is in my actual case) ?