Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
2 Answers
- ignacionr2Lv 42 decades agoFavorite Answer
An alternative to inheritance is containment. You may have a component that needs to extend another component.
If you cannot in a practical way use inheritance (i.e. you don't have a cross-language possibility, or access to the source code, like with COM -the Component Object Model-, or if you would need to inherit the behaviour of more than one component and your language doesn't allow for multiple inheritance) you may implement the base object's interface and delegate every call made to your new class into the contained object, changing and extending whatever part of the original behaviour you may find appropiate.
Source(s): See "Inside OLE 2" by Kraig Brockschmidt - 2 decades ago
A lot of copy-and-pasting. The whole point behind inheritance is to expand on an existing class. You're perfectly able to create all your classes apart from eachother, but if they differ only in a few areas, you're better off creating a base class with the common functionality and then creating subclasses that expand on that functionality in specific ways.