I've never really been poised with this question: But would it be a terrible crime to call base.SomeMethod() conditionally in an overridden method?
Example as in:
protected override void SomeMethod()
{
if( condition > 0 )
base.SuperMethod();
}
I'm aware that this may be considered bad practice but I've actually never read such a claim so far.
I can't think of a reason why this would be bad off the top of my head.
It'd be a lot worse to override the base method and copy the base method's functionality to conditionally call instead of just calling the base method.
class HardHearingPerson : Person
{
override void Listen()
{
if (volume.Acceptable())
base.Listen();
}
}
Guess it depends on the context, but I am sure it could have justified usage.
I do this quite often. Every time I need to "do something more" in a method I override it do my stuff and invoke the base method (or vice versa)
I think it is totally acceptable. You might want to override the behaviour of a base class method only under certain circumstances, or extend the behaviour by calling the base method then doing your own thing.
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