Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 ODB Design Handling Inheritance in ODL M. Akhtar Ali School of Informatics.

Similar presentations


Presentation on theme: "1 ODB Design Handling Inheritance in ODL M. Akhtar Ali School of Informatics."— Presentation transcript:

1 1 ODB Design Handling Inheritance in ODL M. Akhtar Ali School of Informatics

2 OO Database Design – Lecture 3 DMD (CG156/CG191) 2 Lecture outline Modelling with inheritance Different kinds of inheritance Single verses Multiple Inheritance Inheritance of Behaviour Inheritance of State Handling inheritance in ODL Summarizing OODB Design Representing Classes, Attributes and Operations in ODL Representing Associations in ODL Representing Inheritance in ODL

3 OO Database Design – Lecture 3 DMD (CG156/CG191) 3 Modelling with Inheritance Inheritance is usually termed as specialization/generalization relationship among super-classes and sub-classes. Super-class: An entity type or class that includes one or more distinct sub-groupings of its instances. Sub-class: A distinct sub-grouping of instances of an entity type or class. Each instance of a sub-class is also an instance of the super-class. Generalization relationship specifies that a super-class generalizes the properties of several sub-classes. The Super-class contains the properties and behaviour that the sub- classes share. All Sub-classes inherit the properties and behaviour of the super- class. Specialization relationship specifies that several sub-classes are in some way specialized form of the super-class. A Sub-class may include properties not present in the super-class or other sub-classes thereby making it distinguished.

4 OO Database Design – Lecture 3 DMD (CG156/CG191) 4 Specialization Process The process of maximizing the differences between members of an entity by identifying their distinguishing characteristics. It is a top-down approach to defining a set of super-classes and their sub-classes. Once super-classes and sub-classes are identified, attributes and operations specific to sub-classes and their relationships with other classes are then identified. For example, having defined Person class, we then define Lecturer and Student classes to be sub-classes of Person class. Given the Student class, there are differences between under-graduate and post-graduate students e.g., under- graduate have personal tutors but post-graduates don’t. Also, post-graduate write dissertation where as under-graduate don’t.

5 OO Database Design – Lecture 3 DMD (CG156/CG191) 5 Generalization Process The process of minimizing the differences between members of an entity by identifying their common characteristics. It is a bottom-up approach which results in the identification of a generalized super-class from the original entity types. We try to identify similarities among the original entity types e.g., common attributes, relationships, and operations. For example, full-time lecturers may be module tutor and supervise post-graduate’s dissertations, whereas part-time lecturer only teach on certain modules and work for a department for certain hours. This leads to a generalized Lecturer as super-class of more specialized classes FullTimeLecturer and PartTimeLecturer as its sub-classes. Generalization can be seen as reverse of specialization. In practice, both processes are used to complement each other. That’s we refer to them as specialization/generalization.

6 OO Database Design – Lecture 3 DMD (CG156/CG191) 6 Different kinds of inheritance Single verses Multiple Inheritance In Single inheritance, a sub-class has only one super-class. In Multiple inheritance, a sub-class has more than one super-class. Inheritance of Behaviour A sub-class inherits only the behaviour (operations) of a super- class. The super-class in this case usually only defines operations i.e., an interface. For example, defining a common interface for students and lecturers. It is also known as is-a or is-a-kind relationship. Inheritance of State When a sub-class extends a super-class by adding attributes, operations or relationships and both of them are concrete classes. The sub-class inherits every thing defined in the super-class. For example, Lecturer and Student classes inherit all the attributes and operations of Person class.

7 OO Database Design – Lecture 3 DMD (CG156/CG191) 7 Interface verses Class An interface is a classifier that represents an abstract collection of operations. A class may have one or more interfaces, and an interfaces can group operations of several different classes. Although Person class is super- class of Student and Lecturer, yet it would be useful to define a common interface. Given the Identification interface, we can have several classes that would realize the same interface.

8 OO Database Design – Lecture 3 DMD (CG156/CG191) 8 Example Class Diagram for UNN-IS

9 OO Database Design – Lecture 3 DMD (CG156/CG191) 9 Handling inheritance in ODL The inheritance of behaviour is represented by “ : ” For example: class Person : Identification {...}; Defines that Person class inherits all the operations defined in the Identification interface. The object type after the : must be an interface. The inheritance of state is represented by “extends” For example: class Student extends Person {...}; Defines that Student class inherits all the operations, relationships and attributes defined in the Person class. A class extends another class, an interface may inherit from another interface but not from a class.

10 OO Database Design – Lecture 3 DMD (CG156/CG191) 10 Implementing Inheritance in UNN-IS interface Identification { short getAge(); voidchangeAddress(in Address addr); date getBirthDate(); string getName(); string getGender(); set getAddresses(); }; class Person : Identification {...}; class Student extends Person {...}; class Lecturer extends Person {...}; class UGStudent extends Student {...}; class PGStudent extends Student {...}; class FullTimeLecturer extends Lecturer {...}; class PartTimeLecturer extends Lecturer {...};

11 OO Database Design – Lecture 3 DMD (CG156/CG191) 11 Summarizing OODB Design: Classes Each UML class becomes an ODL class. Each attribute or method in a UML class becomes an attribute or operation of an ODL class with appropriate types. Specify a suitable extent name unless the class diagram explicitly indicates otherwise. Specify a unique key if one or more attributes of a UML class are shown in bold or tagged with {PK}. For a composite attribute, specify a structure literal type. Specify a suitable positive integer type (i.e. unsigned short or unsigned long ) if an attribute / operation of a UML class has type int {+} or integer {+}.

12 OO Database Design – Lecture 3 DMD (CG156/CG191) 12 Summarizing OODB Design: Associations Directed Associations Define single or collection valued attribute of an appropriate type in the pointing class. Bi-Directional Associations Define relationships in both classes with appropriate types and inverses. Aggregations Week: Define a single or collection valued attribute of an appropriate type in the aggregating class. Strong: Define the aggregated class as and define a single or collection valued attribute of the struct type in the aggregating class.

13 OO Database Design – Lecture 3 DMD (CG156/CG191) 13 Summarizing OODB Design: Associations… Association Classes One-to-one: Define a single or collection valued attribute and include the attributes of the association class in one of the participating classes. One-to-many: Define a bi-directional relationship in both classes and include attributes of the association class in the class on the to-many side. Many-to-many: Define a new class for the association class including all of its attributes. Define bi-directional relationships between the new class and the participating classes with appropriate types and inverses. In certain cases (e.g. when navigation from classes at both ends of the association is not required) it be desirable to embed the association class in one of the classes that participate in the association. See an example of this scenario near the end of week 11 lecture.

14 OO Database Design – Lecture 3 DMD (CG156/CG191) 14 Summarizing OODB Design: Inheritance Single Inheritance interface A {...}; class B {...}; class C : A {...}; interface D : A {...}; Multiple Inheritance class E : D extends B {...}; Inheritance of Behaviour class C : A {...}; Inheritance of State class F extends E {...};


Download ppt "1 ODB Design Handling Inheritance in ODL M. Akhtar Ali School of Informatics."

Similar presentations


Ads by Google