Chapter 16: Multiple Inheritance in C


OVERVIEW

C++ allows a class to inherit implementation code from multiple superclasses. This is referred to as multiple inheritance (MI). This chapter has four goals: (1) to present programming scenarios that might justify MI; (2) to describe the programming issues that arise when a class inherits from the same base through multiple paths; (3) to present modifications to the syntax for constructors, copy constructors, and so on, when a class inherits from the same base through different paths; and (4) to present the notions of mixin class and role-playing class for getting around the complications introduced by MI.

Some programmers like multiple inheritance because real-world entities (such as yourself) do inherit traits from multiple sources. In that sense, MI allows for direct modeling of real-world problem domains. But there are also many programmers who shun MI because it can introduce deeply hidden bugs into a large program and can make it more daunting to extend a class hierarchy. In any case, it is good to know that any design that uses multiple inheritance can be converted into one in which a class inherits implementation code from only one superclass.

Java does not allow a class to inherit implementation code from multiple superclasses. However, as was shown in the previous chapter, Java does allow a class to inherit behaviors from multiple interfaces. As we showed there, this allows a Java object to behave polymorphically with respect to different types.




Programming With Objects[c] A Comparative Presentation of Object-Oriented Programming With C++ and Java
Programming with Objects: A Comparative Presentation of Object Oriented Programming with C++ and Java
ISBN: 0471268526
EAN: 2147483647
Year: 2005
Pages: 273
Authors: Avinash Kak

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net