Task:
There is a base class that implements some kind of common functionality used by most children.
But. There are some descendants for which this common functionality should be disabled.
I see three options for solving this problem:
- Internal protected variable in the base class, depending on which the necessary functionality will or will not be executed. The value of this variable sets the base class by default, and the children can change.
- A virtual method of the base class, depending on the return value of which the necessary functionality will or will not be performed. The default value returns the base class method. A child can override this method and return the value it needs.
- The general functionality is carried out in one virtual protected not sealed method. A descendant, if necessary, can override this method, completely removing or changing the desired behavior.
Which solution is better?
Maybe there are other solutions?