Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ceg860 (Prasad)L13MI1 Multiple Inheritance DAG Class Structure : Directed Acyclic Graph.

Similar presentations


Presentation on theme: "Ceg860 (Prasad)L13MI1 Multiple Inheritance DAG Class Structure : Directed Acyclic Graph."— Presentation transcript:

1 ceg860 (Prasad)L13MI1 Multiple Inheritance DAG Class Structure : Directed Acyclic Graph

2 ceg860 (Prasad)L13MI2 Examples in System Modeling combination Multiple inheritance facilitates combination 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 calculator

3 ceg860 (Prasad)L13MI3 roles Multiple inheritance facilitates representation of various roles 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.

4 ceg860 (Prasad)L13MI4 Examples from Software Systems Window ( Hierarchical Structure ) Tree »(features) listOfSubwindows, parentWindow, addWindow, removeWindow, etc. ( Graphical Object ) Rectangle »(features) height, width, position, display, hide, etc.

5 ceg860 (Prasad)L13MI5 Tree List »(features) countChildren, leftMostChild, addChild, removeChild, etc. Cell »(features) parent, nextSibling, etc. Linked list ( leftmost child right sibling )

6 ceg860 (Prasad)L13MI6 Graphics Example Composite_Figure class Composite_Figure extends Figure, LinkedList[Figure] {... void display() { forEachDo { item.display(); }; } void translate() { … }...} Illustrates: multiple inheritance, polymorphic data structure, dynamic binding, recursion, etc.

7 ceg860 (Prasad)L13MI7 Design Pattern Describing composite structures using multiple inheritance with a container class as a parent More Examples »Menus with Submenus »Compound Commands »Graphical Object Groups

8 ceg860 (Prasad)L13MI8 Eiffel’s approach to Multiple Inheritance

9 ceg860 (Prasad)L13MI9 Name Clashes and Feature Renaming Eiffel bans intra-class overloading. feature renamingName clashes resulting from multiple inheritance can be resolved in the child class using feature 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.

10 ceg860 (Prasad)L13MI10 Repeated 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  Share  Share : age  Replicate  Replicate : address A D BC

11 ceg860 (Prasad)L13MI11 Multiple 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.

12 ceg860 (Prasad)L13MI12 Transcontinental Drivers in Eiffel classinherit class French_US_Driver inherit French_Driver rename as address as french_address, as violations as french_violations, as pay_fee as french_pay_fee end US_Driver rename as address as us_address, as violations as us_violations, as pay_fee as us_pay_fee end feature feature... // shared : age, name,... end end;

13 ceg860 (Prasad)L13MI13 Conflicting Redefinitions What if a feature f inherited by class D from repeated ancestor A has been redefined in B and/or C ? v Conflicts under sharing (two impl., one name) Problem: Name Clash  Eiffel provides rename, redefine, and undefine to enable a programmer to disambiguate.

14 ceg860 (Prasad)L13MI14 (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.

15 ceg860 (Prasad)L13MI15 Windows in Eiffel class class Window feature display is … end; classinherit class Window_with_Border inherit Window feature display is … end; classinherit class Window_with_Menu inherit Window feature display is … end; classinherit class Window_with_Border_and_Menu inherit Window_with_Border Window_with_Menu featureis feature display is {Window_with_Border} Precursor; {Window_with_Menu} Precursor; end; Window.display !! Problem: Indirectly invokes Window.display twice!!

16 ceg860 (Prasad)L13MI16 (Cont’d) classinherit class Window_with_Border_and_Menu inherit Window Window renameas rename id as window_id select select window_id redefineend redefine display end Window_with_Border renameas rename id as border_id redefineend redefine display end Window_with_Menu renameas rename id as menu_id redefineend redefine display end feature feature is display is {Window} Precursor; draw_border; draw_menu; end; end end;


Download ppt "Ceg860 (Prasad)L13MI1 Multiple Inheritance DAG Class Structure : Directed Acyclic Graph."

Similar presentations


Ads by Google