Unformatted text preview:

Multiple InheritanceExamples in System ModelingPowerPoint PresentationExamples from Software SystemsSlide 5Graphics ExampleDesign PatternEiffel’s approach to Multiple InheritanceName Clashes and Feature RenamingRepeated InheritanceMultiple Inheritance of FeaturesTranscontinental Drivers in EiffelConflicting Redefinitions(cont’d)Windows in Eiffel(Cont’d)ceg860 (Prasad) L13MI 1Multiple InheritanceClass Structure : DDirected AAcyclic GGraphceg860 (Prasad) L13MI 2 Examples in System Modeling Multiple inheritance facilitates combinationcombination of (orthogonal) abstractions.•Company plane•Airplane (Pilot’s perspective)•(queries) passenger_count, altitude, position, speed, etc.•(commands) take_off, land, set_speed, etc.•Asset (Accountant’s perspective)•(features) purchase_price, resale_value, depreciate, etc.•Dining car•Train car (coach)•Restaurant •Watch calculatorceg860 (Prasad) L13MI 3Multiple inheritance facilitates representation of various rolesroles of an object.•Sofa bed, Mobile home, ...Knowledge Representation  Clinton is a father. Clinton is the ex-President of USA. Nixon was a Republican. Nixon was a Quaker. Dolphins are aquatic creatures. Dolphins are mammals.ceg860 (Prasad) L13MI 4Examples from Software Systems •Window•(Hierarchical Structure) Tree»(features) listOfSubwindows, parentWindow, addWindow, removeWindow, etc.•(Graphical Object) Rectangle»(features) height, width, position, display, hide, etc.ceg860 (Prasad) L13MI 5•Tree •List»(features) countChildren, leftMostChild, addChild, removeChild, etc.•Cell»(features) parent, nextSibling, etc. Linked list(leftmost child right sibling)ceg860 (Prasad) L13MI 6Graphics Exampleclass Composite_FigureComposite_Figure extends Figure, LinkedList[Figure] { ... void display() { forEachDo { item.display(); }; } void translate() { … }...} Illustrates: multiple inheritance, polymorphic data structure, dynamic binding, recursion, etc.ceg860 (Prasad) L13MI 7Design Pattern Describing composite structures using multiple inheritance with a container class as a parent •More Examples»Menus with Submenus»Compound Commands»Graphical Object Groupsceg860 (Prasad) L13MI 8Eiffel’s approach to Multiple Inheritanceceg860 (Prasad) L13MI 9 Name Clashes and Feature Renaming •Eiffel bans intra-class overloading.•Name clashes resulting from multiple inheritance can be resolved in the child class using feature renamingfeature renaming mechanism.•Redeclaration/redefinition changes the feature, but keeps the name. Renaming changes the name, but keeps the feature.•Redeclaration is semantic; renaming is syntactic.•Renaming also enables class designers to give locally appropriate names to features.ceg860 (Prasad) L13MI 10Repeated Inheritance •Class D is a descendant of class A in more than one way. E.g., •A = Driver (age, address, birthday(), etc.)•B = French_Driver•C = US_Driver•D = US_French_DriverShareShare : ageReplicateReplicate : addressADB Cceg860 (Prasad) L13MI 11Multiple Inheritance of Features•A class that inherits different but identically named features from different parents is invalid. •Feature renaming may be used to avoid name clash.•Note that this case excludes repeated inheritance.•An attribute coming from repeated ancestor is shared, by default. Feature renaming may be used to replicate it.•In C++, all the fields of a repeated ancestor are either shared (virtual) or duplicated.ceg860 (Prasad) L13MI 12Transcontinental Drivers in Eiffel classclass French_US_Driver inheritinherit French_Driver renamerename address asas french_address, violations asas french_violations, pay_fee asas french_pay_fee endend US_Driver renamerename address asas us_address, violations asas us_violations, pay_fee asas us_pay_fee endend featurefeature . . . // shared: age, name, ... endend;ceg860 (Prasad) L13MI 13Conflicting Redefinitions•What if a feature f inherited by class D from repeated ancestor A has been redefined in B and/or C? Conflicts under sharing (two impl., one name)•Problem: Name ClashEiffel provides rename, redefine, and undefine to enable a programmer to disambiguate.ceg860 (Prasad) L13MI 14(cont’d)•Conflicts under replication (two impl., two names)•Problem: Ambiguity for Dynamic binding A a = new D(); a.f(); Eiffel provides select to let the programmer pick the appropriate impl. to run for f() on a D via a A-entity.ceg860 (Prasad) L13MI 15 Windows in Eiffelclassclass Windowfeature display is … end; classclass Window_with_Border inheritinherit Windowfeature display is … end;classclass Window_with_Menu inheritinherit Windowfeature display is … end;classclass Window_with_Border_and_Menu inheritinherit Window_with_Border Window_with_Menu featurefeature display isis {Window_with_Border} Precursor; {Window_with_Menu} Precursor; end; Problem: Indirectly invokes Window.display Window.display twice!!!!ceg860 (Prasad) L13MI 16 (Cont’d) classclass Window_with_Border_and_Menu inheritinherit WindowWindow renamerename id asas window_id selectselect window_id redefineredefine display endend Window_with_Border renamerename id asas border_id redefineredefine display endend Window_with_Menu renamerename id asas menu_id redefineredefine display endend featurefeature display isis {Window} Precursor; draw_border; draw_menu; end;


View Full Document

Wright CEG 860 - Multiple Inheritance

Documents in this Course
Load more
Download Multiple Inheritance
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Multiple Inheritance and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Multiple Inheritance 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?