ARES, Adding a class and REStructuring Inheritance ... - CiteSeerX

4 downloads 83 Views 287KB Size Report
1. Figures 2 and 3 give examples of such partial orders. In Casais's work Cas92] the height of the partial orders is limited to one level. technical diploma. 3. 0.
ARES, Adding a class and REStructuring Inheritance Hierarchies H. Dicky, C. Dony, M. Huchard, T. Libourel LIRMM, 161 rue Ada, 34392 Montpellier Cedex 5, France, email: [email protected] February 27, 1995

Abstract

In Object-Oriented systems, the design of hierarchies needs a man-machine interactivity but should bene t from automatic tools. We describe in this paper an incremental algorithm which is a rst attempt to automatically insert a class in an existing inheritance hierarchy and thus can be used to build and reorganize such hierarchies. Our algorithm works with a model of hierarchies based on what we call the "Galois SubHierarchy" which is a particular suborder of the Galois lattice. The use of a Galois SubHierarchy to build hierarchies has been introduced recently by [GM93] and is described more precisely in this paper. We think, as [GM93], that the Galois SubHierarchy is especially relevant to the building of the hierarchy. Moreover, the Galois SubHierarchy provides a much more ecient (in space) way to represent hierarchies, than the Galois lattice. The proposed insertion algorithm is incremental, performs maximal factorization of properties that are de ned on the classes and o ers a rst solution to the problem of property overloading. We show that this algorithm maintains a Galois SubHierarchy without building the whole Galois lattice, and we conclude with examples of problems which arise when applying the incremental algorithm to concrete situations. Key words : Inheritance hierarchies, Galois lattice, Restructuring, Factorization Category : Research Topics : reuse, design methods, software engineering, databases

1

1 Introduction In object-oriented systems, inheritance hierarchies are generally built \by hand" by a designer or a group of designers after an analysis step. The underlying construction methods are mostly informal and empirical. It seems very dicult to completely automatize the construction of hierarchies because of the number of criteria to take into account, and due to the diculty in de ning what is a \good" hierarchy independently of the context. However the process of structuration should bene t from a partial automation, especially when the classes to be structured become more intricate and numerous. Some parts of the task are repetitive, (as for example building classes to factorize properties common to several classes) and human work does not ensure that the same situation will systematically be handled in the same way. The hierarchy design may be done in a global way, given a set of unrelated classes to be organized. A contrario, incremental methods can be used in order to insert a class. This class could be de ned by the designer or, in object-oriented databases framework, could be a virtual class (\view class"), computed on other classes. One of the main interest of inheritance hierarchies is to share descriptions and behavior common to several classes. In this paper, we focus on one essential activity when we build inheritance hierarchies: to point out these common properties and create classes to store them (\factorize common properties"). We propose an incremental algorithm which performs maximal factorization of properties de ned on the classes, and o ers a solution to the problem of property overloading. Di erent methods are proposed in existing systems [Cas92, LBSL91, LBSL90, Ber91] to solve that factorization problem. We extend them, rstly by approaching the question of overloading, secondly by producing a more simple polynomial algorithm, thirdly by producing results that can be theoretically characterized. Our frame of reference to describe the algorithm is Galois lattices, already much used in other domains (e. g. machine learning, information retrieval, knowledge representation), which provides, as noticed in [GM93], a nice point of view on that factorization problem. Section 2 introduces various de nitions and notations. Section 3 explains what Galois lattices can bring to inheritance hierarchy building. Section 4 details the incremental algorithm and its main properties. The paper ends with a general discussion about the application of the algorithm.

2

2 De nitions and Notations We here give the notations used in the following of the paper.

2.1 Inheritance Hierarchy An inheritance hierarchy H is a directed acyclic graph (C ; ?) where C is the set of classes, and ? the set of the inheritance directed edges. H induces a partial order which we denote by H : thus a class is taken into account after all its superclasses. We shall consider the following linear extension of Figure 9: , Person, Researcher, Teacher, TeacherResearcher, Administrator, Teacher-Researcher-Administrator. For any class C , the properties of Declared(C ) are in roman-face, when italics are used for the properties of Inherited(C ) 6 . For the class Invited-Prof, italics are used for the \potential properties". Firstly the classes , Person and Researcher are explored: their properties set is included into the properties set of A, thus they are superclasses of A 7 . While exploring class Teacher, the algorithm creates a class, that we call Able to teach , in order to factorize the properties declared by Teacher and that belong to Properties(A), here fdiploma1g. Able to teach is superclass of Teacher and subclass of the superclasses common to Teacher and A, i. e. Person. The edge (Teacher, Person) becomes a transitivity edge and disappears. Such an extraction upon the class Teacher-Researcher produces the class Able to Teach in High School . The exploration of Administrator and Teacher-Researcher-Administrator has no e ect. A is linked to its immediate superclasses, in the example, to Able to Teach in High School . In Figure 10, A has no subclass, since no class of H owns all the properties of A. 00

00

00

00

00

00

00

00

4.2 Speci cations Input :

The algorithm starts with Hi = (Ci ; ?i ) a class hierarchy with root 8 and with a meaningfull class A, to be inserted. Properties(A) is A properties set. The framework is the naive approach, and in Hi the properties are maximally factorized: thus any property is declared only once (the transformation described in section 2.2 allow to take overloading into account).

Output :

The nal hierarchy Hf = (Cf ; ?f ) "integrates" Hi and A and respects the following properties, whose demonstrations are in [DDHL94b].

 Maximal factorization of properties We have represented all the inherited properties, including the overriden properties The superclasses of A appear in Figure 10 in rectangular boxes 8

has no properties

6

7

10

Ω INVITED_PROF

diploma0 diploma1 diploma2 salary0

PERSON name diploma4 salary2 laboratory

name diploma0 salary0

RESEARCHER

ADMINISTRATOR

TEACHER

name diploma0 salary0

name diploma0 salary0

diploma2 laboratory

diploma1 salary1

name diploma0 salary0

admin_unit

TEACHER_RESEARCHER name diploma0 diploma1 diploma2 salary0 salary1 laboratory

diploma4 university

TEACHER_RESEARCHER_ADMINISTRATOR name diploma0 diploma1 diploma2 diploma4 salary0 salary1 laboratory university admin_unit

salary3 nb_students

Figure 9: Initial step

 Transitive closure preservation of the hierarchy: For all the classes of Hi still belonging to Hf , the inheritance pathes remain.  Conservation of the properties of input classes: Classes which belong to both hierarchies Hi and Hf keep the same set of properties.  Meaningfull classes conservation: The set of meaningfull classes of H is C SfAg f

Mean

4.3 Description For presentation reasons, we give the algorithm in two steps, and only detail the rst one:

 LookFor&BindSuperClasses recognizes A superclasses and binds A together with its immediate superclasses.

 BindSubClasses binds A together with its immediate subclasses. We do not speak about transitivity edges. A fully detailed algorithm is to be found in [DDHL94b]. Besides the already given notations, the algorithm uses some global variables : 11

Ω PERSON name diploma0 salary0 "Able to Teach" name diploma0 salary0

diploma1

ADMINISTRATOR

RESEARCHER

name diploma0 salary0

name diploma0 salary0

admin_unit

diploma2 laboratory TEACHER name diploma0 diploma1 salary0

salary1 "Able to Teach in High School" name diploma0 diploma1 diploma2 salary0 laboratory

diploma4 TEACHER_RESEARCHER name diploma0 diploma1 diploma2 diploma4 salary0 salary1 laboratory

INVITED_PROF

university

name diploma0 diploma1 diploma2 diploma4 salary0 laboratory

salary2 TEACHER_RESEARCHER_ADMINISTRATOR name diploma0 diploma1 diploma2 diploma4 salary0 salary1 laboratory university admin_unit

salary3 nb_students

Figure 10: Final step

 AalreadyCreated a boolean which is true if and only if a class whose set of properties equals A properties set is found or built as a factorization class. AalreadyCreated starts as false.  SH the current set of A superclasses. SH starts empty.  EmptyClasses, the set of the unmeaningfull classes whose set of declared properties has been cleared out. EmptyClasses starts empty. Algorithm begin

ARES (H ,A) i

LookFor&BindSuperClasses BindSubClasses

end

The algorithm LookFor&BindSuperClasses visits Hi going down from , following a linear extension of >Hi . During this visit, A properties set is compared with the set of properties of the visited class. The whole exploration builds SH , the set of A superclasses in Hf . Then A is |if needed| created and bound 12

to its direct superclasses (Create&BindSH ). We end and delete (DeleteEmptyClasses) each class of the set EmptyClasses, since it is unmeaningfull, and at this point does not declare anymore properties. LookFor&BindSuperClasses

Algorithm begin For every vertex // i is an

LEH V isit(C; A)

C

following

LEH

i

do

arbitrary linear extension of H starting from root

i

endFor

end

Create&BindSH DeleteEmptyClasses

When a class C is visited, let us remember that all its superclasses have already been visited. V isit deals with the easy cases when either C is A or C is a superclass of A, and calls Extract whenever a factorization class is needed. V isit(C; A)

Algorithm begin if else if else if end

Properties(A) = Properties(C) then SetMeaningfull(C) S ; AalreadyCreated true Properties(A)  Properties(C) then SH SH fC g Properties(A) \ Declared(C) 6= ; then Extract(C) endif endif endif

The Extract algorithm creates a factorization class C and inserts C into the hierarchy. This factorization class either is A or is stored inside SH . SH holds already visited Hi classes which are A superclasses, as well as the factorization classes (obviously A superclasses) built up in the previous steps. Given a class C , we consider the set S of classes which are C superclasses while belonging to SH , and we call Sups(C; SH ) the minimal elements of S . 0

13

0

Algorithm begin

Extract(C)

T

Create(C ); Declared(C ) Properties(A) Declared(C); ImmediateSuperclasses(C ) Sups(C; SH); S Inherited(C ) = " Properties(C"); ( )S Properties(C ) Declared(C ) Inherited(C ); S ImmediateSuperClasses(C) (ImmediateSuperClasses(C) fC g) n Sups(C; SH) Declared(C) Declared(C) nSDeclared(C ) Inherited(C) Inherited(C) Declared(C ) if Properties(C ) = Properties(A) then SetMeaningfull(C ); AalreadyCreated true; S else SH SH fC g endif if Declared(C) = ; and not IsMeaningfull(C) S then EmptyClasses EmptyClasses fC g endif 0

0

0

0

C 2Sups C;SH 0

0

0

0

0

0

0

0

0

end

When Create&BindSH is called by LookFor&BindSuperClasses, SH contains all A superclasses in the current graph. If A has not already been found, it must be created and bound together with its immediate superclasses. We shall use the function Min(E ) which provides the minimal (for