9
In conventional multiple inheritance, a class must inherit features from all its ancestors. With this proposed generalized method, you can use an embryonic class, in which the classes themselves are instances, to select ancestor subsets without creating a combinatorial explosion in the object diagram. DOV DORl EREZ TATCHER Technion, Israel Institute of Technology SELECTIVE MULTIPLE INHERITANCE est object-oriented method- M ologies support multiple inheritance through the use of super- classes and subclasses and other types of generalization relationships. However, the same methods do not support selective inheritance - inher- itance of just a subset of attributes and methods from an ancestor class. Although some may claim to do so, the solutions they provide are often cumbersome, counterintuitive, and generally impractical. Most require that a class inherit the features (attrib- utes and services) from all its ances- tors. In practice, however, you often want a class to inherit from only a sub- set of ancestors to avoid a contradicto- ry mix of features. Without the ability to select subsets, you can rapidly cre- ate a combinatorial explosion. In this article, we show that having a class inherit features from all its ancestors is an exponential problem and prove theorems about the upper bound on the number of classes you can derive using multiple inheritance. Ure encountered this problem when we attempted to apply object- oriented analysis to the automatic understanding of engineering draw- ings. To solve it, we developed a gen- eralized approach that supports selec- tive multiple inheritance and lets you dynamically select any ancestor subset. Our approach is based on the notion of emb~yonir rlnss - an entity from which classes are instantiated in a manner analogous to instantiating objects from classes. Many of our IEEE SOFTWARE 07407459/94/$04 00 C 1994 IEEE 77

SELECTIVE MULTIPLE INHERITANCE - Technion

  • Upload
    others

  • View
    12

  • Download
    0

Embed Size (px)

Citation preview

Page 1: SELECTIVE MULTIPLE INHERITANCE - Technion

In conventional multiple inheritance, a

class must inherit features from all its ancestors. With this

proposed generalized method, you can use

an embryonic class, in which the classes

themselves are instances, to select

ancestor subsets without creating a

combinatorial explosion in the object diagram.

DOV DORl EREZ TATCHER

Technion, Israel Institute of Technology

SELECTIVE MULTIPLE INHERITANCE

est object-oriented method- M ologies suppor t mult iple inheritance through the use of super- classes and subclasses and other types of general izat ion relat ionships . However, the same methods do not support selective inheritance - inher- itance of just a subset of attributes and me thods f rom an ancestor class. Although some may claim to do so, the solutions they provide are often cumbersome, counterintuitive, and generally impractical. Most require that a class inherit the features (attrib- utes and services) from all its ances- tors. In practice, however, you often want a class to inherit from only a sub- set of ancestors to avoid a contradicto- ry mix of features. Without the ability to select subsets, you can rapidly cre-

ate a combinatorial explosion. In this article, we show that having

a class inherit features from all its ancestors is an exponential problem and prove theorems about the upper bound on the number of classes you can derive using multiple inheritance.

Ure encoun te red this p rob lem when we attempted to apply object- oriented analysis to the automatic understanding of engineering draw- ings. To solve it, we developed a gen- eralized approach that supports selec- tive multiple inheritance and lets you dynamically select any ancestor subset. Our approach is based on the notion of e m b ~ y o n i r rlnss - an ent i ty f rom which classes are instantiated in a manner analogous to instantiating objects f rom classes. Many of ou r

I E E E S O F T W A R E 07407459/94/$04 00 C 1994 IEEE 7 7

Page 2: SELECTIVE MULTIPLE INHERITANCE - Technion

ideas were inspired by inheritance in biological systems, in which the observed features do not expose the entire genetic information.

INHERITANCE

Inheritance is an important feature of object-oriented analysis, which aims

to model human perceptions. Inheri- tance is obtained by the Gen-Spec structure. throunh a structure that lets

odologies and is implemented in some advanced object-oriented languages, like Clos and C++. to simulifv the mo-

Y

specialized classes inherit all the fea- tures of the general ancestor class.

Multiple inheritance implies the inheritance of features f rom many ancestors and is often justified as a way to provide reusable descriptions. I t is found in most object-oriented meth-

Figure 1. Object diagram of wire specializations.

I . I

duction and adaptation of code.' Multiple inheritance improves code

sharing among classes and localizes code that might need modifications,' but hierarchical contradictions3 and lack of flexibility pose problems when you must model systems compactly and intuitively. Current methods, such as those developed by Peter Coad and Ed Yourdon,+ David Embley and col- leagues,' and James Rumbaugh and colleagues,6 have an implicit conven- tion that requires an object inheriting features from more than one ancestor, to must acquire all the features from all its ancestors. T h e r e is no option to select ancestors.

In this article, we use a synthesis of Embley's and Coad and Yourdon's annotations to establish our method for allowing an object to acquire fea- tures from selected ancestor subsets. F igure 1 shows our notation for a model of an engineering drawing:

Central to this synthesis are the Generalization-Specialization and Whole-Part abstractions of relations among classes and objects.

+ A hollow t r iangle poin t ing "

(U'ire) and its base is linked to a spe- cialized class or classes (Arc and Bar). This is a Gen-Spec relation.

+ A solid triangle pointing toward a class denotes a whole (Wire) and its base is linked to the constituent class or classes. Participation constraints are indicated below it (2). This is a Whole- Part relation.

+ A rectangular box denotes a class and has one, two, o r three stacked compartments. T h e upper one always contains the class name; the second, the list of attributes; and the third, the list of methods (services). T h e bottom two compartments are optional, and you can omit them in high-level views to keep from losing the bigger picture. To avoid ambiguity, however, you can- not omit the attribute compartment if you specifc. the service compartment. ~ ~

M A Y 1 9 9 4

Page 3: SELECTIVE MULTIPLE INHERITANCE - Technion

Figure 3. Lattice depicting conventional inheritance in Aircraft classes.

WHY CONVENTIONAL APPROACHES DON’T WORK

To illustrate the drawbacks of con- ventional niultiple inheritance, we analyzed a typical mechanical-engi- neering drawing. Figure 1 shows the object model. Each wire has a width and two endpoints.

T h e object class Wire in Figure 1 is an abstract class (a class with n o objects), with the attribute width and two endpoints. I t is a generalization of two classes: Arc and Bar. Arc is a cir- cular wire with the additional features Center, Radius, and FindAngle. Bar is a straight Wire, with the additional features Intercept and Findslope.

Wi res also contain annotat ion, which includes text and special symbols. A leader is used to annotate the draw- ing. It is usually an arrow accompanied by text that specifies the exact measure (distance o r degrees of an angle) between two sites in the drawing.

Figure 2 shows an object model of a leader structure. T h e Leader object class consists of a Tail and Arrowhead. A tail is a wire, which may be a bar or an arc. A tail that is a bar is called a bar-tail. A tail that is an arc is called an arc-tail. A bar-tail is part of a longitu- dinal dimension set, which measures

I E E E S O F T W A R E

length. An arc-tail is part of an angular dimension set, which measures angle.

Because we view tails of either form in the same way (at a high level), we can define the T a i l object class as being either an Arc or Bar. Thus, Tail could inheri t the relevant features from either ancestor.

T o t h e best of ou r knowledge, existing object-oriented methods do not let you express this relationship because conventional multiple inheri- tance does not support class overload- ing - t h e abil i ty of one class t o dynamically take several forms, yet exhibit the same high-level behavior.

In C++, for example, overloading pertains to methods that can operate on a variety of specialized object class- es. Using late binding, you can delay funct ion resolution until runt ime. However, late binding enables poly- morphism only for lower classes; poly- morphism is not possible for higher classes.

If we used conventional multiple inheritance for the example in Figure 2 , we would get a Tail with a contra- dictory mix of features. T o overcome this, we must create two additional classes: BarTail and ArcTail, which correspond to the bar tail and arc tail, as shown in Figure 2 . - .

Even so, we still need the abstract class Tail, both to avoid repeating Tail’s features in the two new classes, and to account for the aggregation (part-of) relation to Leader. T h e solution is to add two classes through explicit class enumeration. However, as we show in the box on pp. 80-81, combinatorial considerations render this enumeration impractical, even in cases that are only slightly more complex.

T o illustrate, we consider the Gen- Spec lattice from work by Coad and Yourdon,4 in which there are four types of aircraft: Mili taryAircraft , Civi l ianAircraf t , Je tAircraf t and P rope 1 1 e r Ai r c r a ft. T h e se types a re pairwise exclusive: there’s n o such thing as a MilitaryCivilianAircraft or a JetPropellerAircraft. Figure 3 shows this lattice with four additional types: I, an d Ai r c r a f t , S e aL4i r c r a f t , C a r g o - Aircraft, and PassengerAircraft.

W e have further altered the origi- nal C o a d and Yourdon la t t ice by r emov ing t h e pa i r wi s e exclusion re s t r 1 c t i on fro m M i 1 i t a ry C ivi 1 i an - Aircraft (because there could be a plane for both purposes), and we allow amphibious aircraft (LandSeaAircraft) and dual-purpose aircraft (Cargo- PassengerAircraft). T o include all the possible types with conventional mul-

- - -~ __

79

Page 4: SELECTIVE MULTIPLE INHERITANCE - Technion

tiple i n l i e r i t a ice, H ti mu\t esplicitl!. specii\. 54 c l a w s .

~ 1 . 0 shou hoi\ coniplcs t h i n p get U hen !-oti a d c l e i ~ n more ancestors. n e applied the lattice t o the I‘i!-out of a \ilicon chip. l ‘he inheritance lattice in Fi gii re .< li ;I 5 “ce I I s” a n ( I “CI 1 t i tl iict i 11 g l ines .” Each hasic t!pe is a ~ ) i r c c v.hose inheri ted features floii along these lines. \ square dot denote\ “sol- ti e r i n g, ” p h y s i e a I CO n t i ec ti o n Iienveen the line and the class, i vh ic l i can be i ieiveti as the “sink,” a device that r e c e i i w :;otiiething from another

a

d e i icc (the oppositc of the source). Each cell hiis f r o m o n e t o f i )ur

.;qit:ires that connect to the feat~rrcs o f other claL.ses. LI’Iiat class features are inherited depen(ls on the po5ition of the square dot, ;is Figurc 4 illustrates. ‘l’hc (lots on the left are features from Jet. \ i rc ra It ;in tl I .a r i d A i re ra ft; ( ) t i t h e t 0 17 J re ,\ 1 i I i t:i ry Xi rcr;i f t :i t i d ( :;I r p -

.\ircraft; on the right are I’ropcller- 4ircraft a n d Sea4ircraft; and o n the 1) ( ) t t o in a re (1 i 1, i 1 i 3 t i .\ i r c r a f t a t i d Passe nge r-.-\i rcr3 ft. For esa nip1 e , ce I I .Xi in Figiirc 3 has five ancestor classes

f r o m n.hich i t i nhe r i t s fe:itures: J et.4 i rcr ;i f t , Id a ti tl .Ai rc ra ft, (1 ivi I i a t i -

.\ i r c r ;i ft , a t i tl

\ I i I i t a I? .-\i rcra ft. The re are si.; la! ers o f nine cells

c ~ h , >iclcling a total o f 54 cl make i t easier to see the relationships. \\‘e lahe1 ; ind s h o t + connections for onl!- the top la!-er (cells : \ I through :\‘I), ’I’his level descrihes al l the p s i - Mities o f classes that inherit froni Jet- .Aircraft and Lantl.-\ircraft hu t not from Prcplircraft o r Sea.4ircraft.

T h e five tmdetailcd tiottoni l e i ~ l s

1’:i s s en g e r Ai r c r ;I f t ,

, HATHEMATICS OF SELECTIVE MULTIPLE INHERITANCE

multiple inheritance to get Iess cumbersome models. Here we analyze the combinatorics.

The cardinality of an embryonic class A, I A I is the upper bound on the number of possible classes A may yield.

first level that inherits through selective rnuhiple inheri- tance, and let the potential ancestors ofA be A I , ... A,.

single selective multiple inheritance level is

In the main text, we describe how you can apply selective cardinality ofA from selective multiple inheritance connec- tion s E f 1 , ... g] is given by

The cardinality, defined as the upper bound on the num- ~

onnection* Let A be an ‘lass in the ber of possible classes A may yield, occurs when d l g cxdi- nabties are *dependent of each other. n e i r product is therefore the overall result.

Mdtfple-level ~~mactso l r . Suppose A is an embryonic class with dimension range p. The 71 possible direct ancestors are denoted by {A i , ... A,}. with the respective cardinalities

‘ Theorem I: The cardinality of an embryonic class from a

(1) ‘=J {lAr I, ... IA,J}.

where the dimension range is p =(n,j, k}. The proof for this is as follows: Every i-tuple {Ax,, ...

Ax$, i E J, ... k, andAxi, E (AI, ... A,} is a possible combina- tion of ancestors. The order of ancestors within each i-mple is not important, and you cannot choose an ancestor more than once for the same i-tuple. The number of different i- tuples to be chosen from n ancestors is thus i out of la.

Because you must account for the value of i within the range o f j and k, you get the result in Equation 1. (In the special case ofj=l and k=a, the cardinality is 2’ - 1). The combinatorial nature of the problem is already becoming apparent, even in this simple case.

Them-ewz 2: Let A be a g-dimensional embryonic class and pi the dimension range of each selective multiple inheritance connectton I , respectively, where i E (1, ... 9).

L e t j 4 r S k be the number of direct ancestors to appear 1 in A.&. Let r (n,r) be the set of all r out of n possible r- tuples of distinct ancestors chosen from these n ancestors.

LetT E r be a single T-tuple, consisting of r ancestors {1, ... a); s E (1 ,... r}. ardinality of 7, l yl , is the product of the cardinali- I

ties of each of its elements. That is, r

s = l IYI ( r ) = n IAV3 I (3)

where vs f vt Vs,t E (1 ,... r}, vf, vt E f 1 ,... a}.

all result is the product of the cardinalities.

of all the r out of n r-tuples it contains. That is,

Following the arguments given for Equation 2 , the over-

The cardinality of r. I r I , is the sum of the cardinalities

lrl (nqr) = Clrl (4.) The cardinality of 4 is

Ysr IAl(pl.g)= fi 5 (n’)Vi~{l , . . .g) 4

’The proof for this is as follows: From Equation 1, the

(2) The proof of this is as follows: Each y contributes I yl to

the overall result. T o get I rl , the upper bound on the num- her of ancestor combinations, you must sum over the entire

1 1

s = l y = j s

I

Page 5: SELECTIVE MULTIPLE INHERITANCE - Technion

have the same connections on the tops ' class en~inieration is that it is counter- and hottorns of the cells, hu t show ~ intuitive to human perception of the connections to Prop-.Aircraft and Sea- ~ real world, and can result in loss of Aircaft, not to Jet-Aircraft and 1,anct- ' coherence.- A J ~ overloaded class with 'Aircraft. all its variants frequently results in the

T h e numher o f classes possihle if introduction of artificial intermediate you explicitly enunierate all the possi- abstract classes, whose only function hle combinations using conventional is to let you derive specialized classes. multiple inheritance grows exponen- tially with the number of ancestors, leading to a combinatorial explosion. T h e box below shows this mathemati- cally.

Another disadvantage of explicit

EMBRYONIC CLASSES

To overcome the drawbacks of con- ventional multiple inheritance, we pro-

of an embryonic class A f of th is is based on the proof for th . € A from selective multiple ids

ntical parameters; therefor apply theorem 3, withjd,

Thus, IF1 = 6 + 9 = 1 5

8 1 I E E E S O F T W A R E

Page 6: SELECTIVE MULTIPLE INHERITANCE - Technion

c Class I I

I Feature values assianed I

Behavior Object

has Assigned set of feature values

Assigning

to features instantiated by values

instantiated to -

Class Embryonic (lass Set Set of sets of feature of feature values values

,ks i ning a va/?ie to the - ancestor list

Object Class

pose the use of selective multiple inher- itance that is Imed on niibiyoni 1&.7n-e.c. An embryonic class contains a default attrihute called rrncesmi- list, whose value for a particular class is a list of ancestors from which the class inherits its fea- tures . T h e value assigned t o ances- tor list, .a, determines each class’s fea- ture set and gives rise to a different, distinct class, de-fined by its ances- tors.

An i in p I i ci t me thod , to 7.m ril i i te, accepts AL as a parameter and con- structs the internal structure accord- ingly. ,.U, is somewhat siniiliar to the superclass list in Clos, which lets you crea te classes as t hey a r e needed (dynamically) by using a metaclass protocol feature to insert a class into another class’s superclass list.’

LVith selective multiple inheri- tance, a class may inherit features from any number Ti7 of a given s e t o f 71

~~ ~~~~~ ~ _ _ _ _ _ _ _ ~ ~ ~~~

~ ~~~~~~ ~~

ancestor classes. A class’s di7wt i i71~wtor is a first-generation ancestor, which iniplies that it is located on the hierar- chy l e ~ l just above the class. An a r t i i ~ ~ nrrcwtol- is an ancestor that is a mcniber of the class’s ancestor list. An active ancestor is no t necessarily a direct ancestor.

F igure S shows a ine tamodel (niodel that descrilxs other niodels’) of t h e ent i ty instantiation path. A rounded rectangle denotes an entity instantiation level. Each hox to the

~ right of the rounded rectangles repre- ~ sents a transition t m x , whose irpper

section holds the trigger for thc transi- t ion and lower sec t ion holds t h e instantiation action.

As the figure shows, there arc three e n t i q types: object, class, and einhry onic class. Table 1 sumtnarizes the characteristics of the three types and d e in on s t r a t e s t h e si i i i i 1 a ri ty o f t h e

~~~~ ~~~ ~ ~

~

~~~~ ~~

transitions from class to ohject and eml)qonic class to class. T h e basic dif- ference is that, in conventional tnulti- ple inheritance, an entit\. is first a class then k i n object. In selective multiple inheritance, an enti? is first an e n i t q - onic class, then ;I class, then an object.

Just as a class has a set of features, an embryonic class has a set of‘wfs if

f i v r t r r r . 1 ~ . Instantiating :in ohiect of a class iniplies assigning a value to each of its features, 14 hile instantiating a class of an enihryonic class implies assigning a value to its ancestor list.

F r o m ;i t o p - d o ~ n view of t h e instantiation hierarchy, you can only know exactly what an object looks like and i ts se t of fea tures and t h e i r assigned values h y examining t h e object itself. If you look at a class, you can tell what the object looks like only to the extent of how feahires charac- terize it. If you look at an embryonic class, y o u can tell what an instantiated class looks like only to the extent of wha t possible fea ture se t s i t may assume. Thus, if you view an ohject f rom t h e bo t tom - u p , you can t e 1 I exactly what class it belongs to because you know the exact set o f features. Rut given a class, you cannot coinpletely specifj. the originating embryonic class hecause the class reflects only a subset of the entire feature set.

In conventional terms, you define classes during the structural analysis of the problem, and classes reflect the nature of the objects you dynamically i n s ta t i ti a t e f rom t h e i n . Borrow i i i g f ro i n program mi n g terminology , ;i class structure is defined and known at “coinpile time,” but classes ant1 their ohiects are instantiated and nssigned actual values at “runtime.” T h e intro- duction o f enihryonic classes makes them the compile-time entities, while class instantiation is done during run- time, hefore ohject instantiation.

IMPLEMENTATION

Lf’e implementecl selective multiple inheritance at one inheritance level and then at multiple levels.

82 M A Y 1 9 9 4

Page 7: SELECTIVE MULTIPLE INHERITANCE - Technion

Single-level. When there i s only one inheritance level, a class inay inherit features from 711 active ancestors out of a given set o f iz direct ancestors.

Le t .41, '42, ... A,, denote the 77

direct ancestors of class A, a s shown in Figure 6. A new symbol for selective multiple inheritance combines the hol- low triangle that denotes a <;en-Spec relation with a smaller inverted solid triangle. 'The parameters; (j 2 1) and k (k 5 ?I ) at the left and right corners of the triangle represent the minimum and maximum allowed n u m b e r o f a n ce s t o rs , res 13 ec ti ve 1 y . 'l'h e I owe r hound on the number of active ances- tors is 1 hecause, if; were equal to 0, the inheriting class could not inherit features from any of its ancestors, which would render selective tnultiple inheritance meaningless.

T h e value of class ) o s ancestor list i s denoted as X.AL = {L4,y,, A,,, ... A,J, where X is a class derived from the embryon ic class A , with m active ancestors. That is

, l,, E {,,!I ._. .'I//] v/ = [ I .... ?U]

An embryonic class may have inore than one selective multiple inheritance connection. Each such connection stands for a single d i?~ens ion of the embryonic class. I\ dimension of an enihryonic class i s a high-level attribute that is assigned ;I unique, immediate selective-multiple-inheritance conncc- tion. Each dimension is an aggregation of m out of I I lower level tlimensons of the inheriting class and is assigned a unique, immediate synil)ol for selective multiple inheritance. Each dimension has its own symbol for selective multi- ple inheritance with the tliniension nanic next to it.

If there i s more than one selective- multiple - inheritance connection at th e same l e d , you may want to permit a lower hound of 0 on .j instead o f 1 . 'I'his would extend tlesihility by letting an embqonic class select only a suhset of its possible dimensions.

Figure 7 shows an enihryonic class with ,c dimensions. A cti;rliem-io7z r7777,ce i s

-7- - - -1 .. -

k } from which a class may select its active ancestors, where n,j, and k are the possible, minimal, and maximal number of active ancestors, respectively.

Each selective multiple inheritance connection i E (1, ... g} has its own dimension range. Let X be a g-dimen- sional instance of the embryonic class A. X inheri ts f rom vi; direct active ancestors through selective multiple inheritance connection i; i E { 1 , ... ,y}. 'I'he AI. of X is the union of all the direct active ancestors from each one of the selective multiple inheritance connections, as follows:

the ranFe denoted 11) the triplet p = 1 7 7 , ~ . R here 'A,,, 1 5 the x t i w 'incem)r / ot ~~ -~~ ~~ ~ ~

I E E E S O F T W A R E

class X, obtained from selective multi- ple inheritance connection i.

Multiple inheritance levels. With multi- level multiple inheritance, the AI,s of the ancestors are inherited curnula- t ively, such t h a t AL recursively hecomes a list of lists.

A class with m active direct ances- tors has ?U+ I lists within its .U,, ;is fol- I ows :

X...\I. = { { , I .,., . I.,.?. ... . f , , , , ] , (..I,, AI,] , {..l,v,.AIJ, ... {.Jv .AI>})

111

where S i s a class, d4-vl; i =1, ... 711, are the names of the direct active ances- tors, and L4,v,..4L are the 41,s of every AV;, respectively. T h e first list is of length 712, and contains the names of t h e class's active d i rec t ancestors. Each of the remaining 717 lists is the AL of the corresponding active direct ancestor which, in turn, may contain other lists.

Figure 8 shows the general inhcri-

praph. You recursively assign tance lattice represented as

~~~ ~~~ ~ ~~

83

Page 8: SELECTIVE MULTIPLE INHERITANCE - Technion

~ inherited fe<itures by p'issiiig seri'illy ".

B H tvno nnriniitw through edch AL element, i n ettect pertortning '1 brexith-first se'irch on the graph.

Lye built the 'incestor list in '1 form t h a t co r re sponds t o this t l p e of se'irch, bu t i f a depth-first se'irch I S

b e t t e r f o r s o m e reason , you can implement it in J siinilar way hp coti- structing the 'incestor list in the fol- lowing form:

froin the eiiihryonic class E'. By assign- ing differerciit values to AL, you CJII let the embryonic class take one of 1 5 class forms SI, ... Xly.

Because t h e order in U hich t h e active ancestors are listed is no t sig- n i fi c a n t , s o ti1 e of the co in tii n a t i 011 s are identical ancl therefore redun- dant. *l'hus, S,, = XI, = SI;, '7;- = X13, and *YIl = S,, , so i n effect you have only 1 1 different class forms rather than 1 i.

You can easily eliiniiiate redun- dancy of this kind as you detect i t dur ing the recursive assignment of inherited classes. Thus , n o class is inserted more than once i n t o Al,, which makcs it linear.

T h e order of the elements in AL c le te rmines t h e o r d e r o f f e a t u r e assignment, and you can use i t to suppor t t h e resolution of rnultiple

In Figure 8, X is a class derived

L L

i nhe r i t ance conf l ic t s a t t h e class level. '1.0 do this, you apply the con- vention that the first value encouii- t c re tl tlu r i n g t h e re cu rsi ve assign- ment overrides a l l others.

Figure 9 shows how with selective multiple inheritance, the inheritance 1 a tt i c e is d rain a t i c a I I y red u c - e d t o achieve a clearer and more intuitive representation. T h c r e is on ly o n e e 111 t i r yo n i c c 1 ass, Specific- ,Ai rc r a f t , instead of the 54 classes in Figure 3 .

In addition to the obvious reduc- t ion of r edundancy , t h e r educed scheme captures the intuitive ohser-

~ ~~~ ~~ ~~~~ ~~~~ ~~~~~~ . ~~~ ~

84

Page 9: SELECTIVE MULTIPLE INHERITANCE - Technion

v:i t i o t i t h ;it S p e c i f i c A i rc r ' 'I f t c a n i t i cl U d e 111 i 1 i t a r!. i t se , P ropu Is i on , T A tiding cap a hi I i ty and LIS a ge.

SPECIAL CASES

. i p 13 1 i c:i t i o ii s ha \ c iii ;i 11 y 11 e e d s. Sometimes y o u will not need the hill selective capabilities of selective multi- ple inheritance. You c;in still adapt tlie method to this and other special cases.

+ Cor, z t i tic) mii 717 idtipie in her -itcinc-c. T o adapt the notation for cotiventicm- al multiple inheritance, !-ou simply delete the small solid triangle from the selective multiple inheritance tri- angle. T h i s is equivalent t o using se I e c t i vc mu1 ti 1) I e i n h e r i ta n ce \v h i 1 e specifying j = k = r i , which results in a cardinaliq of I , since in coni-entional multiple inheritance all the r / m c e s - tors ;ire active, a n d no selective inher- itance is enabled.

+ Chnr~'.'bL,ii.'i~~, nrirltiplc i t ihc~r- f d 7 1 1 ~ ' . Y o u iiia!. need this when 311

possible coii1l)inations are legal. '1'0 ad apt s tail d a rtl notation to this cas e , you delete j a n d k from the selective multiple inheritance symtml. Th i s is the saiiie as stating that j = 1 and k=n, which gives a cardinalitj~ of 2'' - 1, the most nonrestrictive option possiihle.

need this when you have 11 (more than , the classes share 21 suhset

o f features , and a n oh jec t c a n n o t inherit froin m i r e than one class. h i

example is opcrator (or function) overloading, M hich is irnplementcd in 1 an gu a ges 1 i k e C + + . Implement i n g tnuhial esc~usioti with selective multi- ple inheritance implies thatj=k= 1. 'I'he emtiryonic class inherits a l l the fea- tures from cxxtly one out of 11 ances- tors, yieltling I r different classes.

+ '1 lritiilil(y e.wiiisive h.

e h;.i\,e shown that conventional W mu1 ti ple in he ri tance , H hi c h ad- vocates the explicit enunieratioii of all possi hl e at t r i I N te coni b i t i at i o t i s ! t i o t only leads to a coml)inatorial explo- sion even for ii motlest nuniber of ancestors, but might also result in a

I E E E S O F T W A R E

cou t i te r i n t u i ti v e a n d cu i n t)e rs o ti1 e analysis.

S e I e c t i ve m u I ti 13 1 e i n h e r i t a r i ce address e s t h i s we a k n e s s, a t i d we helieve it u.ill enhance existing object- oriented analysis methods and coti- trihute an important 1)uilding block to the theory of multiple inheritance.

Ohject-oriented programming I v i -

~~~~ _ _ _ _ _ ~ ~ ~ ~ ~ ~

1 ACKNOWLEDGMENTS

guages are considered powerful to a large extent because of their ability to handle inheritance at various levels of sophistication. Applying selective tnul- tiple inheritance in such languages is likely to strengthen them I)!, drattiati- cally improving code sha r ing and coherency through a better inheri- tance mechanism. +

85