Don't burn your base class
Line 1: | Line 1: | ||
This is a comment on the use of inheritance, and is especially applicable to object-oriented programming languages that employ a single inheritance model. | This is a comment on the use of inheritance, and is especially applicable to object-oriented programming languages that employ a single inheritance model. | ||
− | A designer has | + | A designer has "burned" their base class when they have, perhaps unnecessarily, used inheritance to access the attributes and/or behaviours of another class. In a single inheritance model, they have consumed or "burned" their one chance to inherit. |
+ | |||
+ | It is often not obvious that a designer has "burned" their base class until a more appropriate use for inheritance is discovered. In this situation it may be beneficial to replace the original use of inheritance, so that inheritance may be used where it is most necessary. Obviously, this is not usually such an issue in multiple inheritance models. However, unnecessary use of inheritance still has negative effects such as increased rigidity. | ||
If a designer has “burned” their base class, it may be inferred that the designer has misused the inheritance model. This can be the case where the inheritance relationship does not represent a specialisation of the base class, or does not take advantage of polymorphism. | If a designer has “burned” their base class, it may be inferred that the designer has misused the inheritance model. This can be the case where the inheritance relationship does not represent a specialisation of the base class, or does not take advantage of polymorphism. | ||
− | In some cases, a designer can force a client to | + | In some cases, a designer can force a client to "burn" their base class by providing access to functionality or behaviours via inheritance only. This will then limit how the client can make use of inheritance in their own design. |
==Refactor With== | ==Refactor With== |
Revision as of 04:06, 18 July 2009
This is a comment on the use of inheritance, and is especially applicable to object-oriented programming languages that employ a single inheritance model.
A designer has "burned" their base class when they have, perhaps unnecessarily, used inheritance to access the attributes and/or behaviours of another class. In a single inheritance model, they have consumed or "burned" their one chance to inherit.
It is often not obvious that a designer has "burned" their base class until a more appropriate use for inheritance is discovered. In this situation it may be beneficial to replace the original use of inheritance, so that inheritance may be used where it is most necessary. Obviously, this is not usually such an issue in multiple inheritance models. However, unnecessary use of inheritance still has negative effects such as increased rigidity.
If a designer has “burned” their base class, it may be inferred that the designer has misused the inheritance model. This can be the case where the inheritance relationship does not represent a specialisation of the base class, or does not take advantage of polymorphism.
In some cases, a designer can force a client to "burn" their base class by providing access to functionality or behaviours via inheritance only. This will then limit how the client can make use of inheritance in their own design.