3.4. Type Inheritance and EER diagrams

In this lecture we look at...
[Section notes PDF 117Kb]

3.4.01. Introduction

  • Design/schema side (Entity types)
  • Object-orientated concepts
    • Java, C++ or UML
    • Sub/superclasses and inheritance
  • EER diagrams
  • EER to Relational mapping

3.4.02. OO

  • Inheritance concept
    • Attributes (and methods)
  • Subtypes and supertypes
  • Specialisation and Generalisation
  • ER diagrams
    • show entities/entity sets
  • EER diagrams
    • show type inheritance
    • additional 8th step to ER→Relational mapping

3.4.03. Objects

  • Basic guide to Java
  • Object, classes as blueprints
  • Object, collection of methods and attributes
  • Miniworld model of real world things
  • Object, entity in database terms

3.4.04. Abstract

  • Similar objects
  • Car Park example
  • Student example
  • Shared properties/attributes
  • Generalisation
  • Reverse, specialisation

3.4.05. Relationships

  • Using English as model
  • ‘Is a’ (inheritance)
  • ‘Has a’ (containment)
  • Nouns as objects
  • Verbs as methods
  • Adjectives as variables (sort of)

3.4.06. Classes

  • Superclasses (Student)
  • Subclasses (Engineer, Geographer, Medic)
  • Inheritance
  • Subclass inherits superclass attributes
    • Union of specific/local and general attributes
  • Inheritance chains
    • Person → Student → Engineer → Computer Scientist

3.4.07. EER Fruit example

  • Partial participation
  • Disjoint subclasses
  • A fruit may be either a pear or an apple or a banana, or none of them. A fruit may not be a pear and a banana, an apple and a banana, an apple and a pear …

Extended Entity-Relationship diagram showing partial participation in disjoint subclasses

3.4.08. EER Wine example

  • Total, disjoint
  • Equivalent to Java Abstract classes
  • A Wine has to be either Red, White or Rosé cannot be both more

EER diagram showing total participation in disjoint subclasses

3.4.09. More extended (EER)

  • Specialisation lattices
    • and Hierarchies
  • Multiple inheritance
  • Union of two superclasses (u in circle)
  • In addition to basic ER notation

3.4.10. EER diagramatic notation

  • Subset symbol to illustrate
  • sub/superclass relationship
  • direction of relationship
  • Circle to link super to subclasses
    • Disjoint
    • Overlapping
    • Union

3.4.11. Disjointness constraint

  • Disjointness (d in circle) – single honours
  • Overlapping (o in circle) – joint honours/sports
  • Membership condition on same attribute
    • attribute-defined specialisation
    • defining attribute
    • implies disjointness
  • versus user-defined
    • each entity type specifically defined by user

3.4.12. Completeness constraint

  • Total specialisation
    • Every entity in the superclass must be a member of atleast 1 subclass
    • Double line (as ER)
  • Partial specialisation
    • Some entites may belong to atleast 1 subclass, or none at all
    • Single line
  • Yields 4 possibilities
    • (Total-Dis, Total-Over, Partial-Dis, Partial-Over)

3.4.13. EER Chip example

  • Total, overlapping
  • A Chip may has to be at least one of FPA Unit, Reg Block, L1 Cache, and may be more than one type

EER diagram showing total participation in overlapping sets

3.4.14. EER Multiple inheritance

  • Type hierarchies
  • Specialisation lattices
  • Well, sir, the Supreme Court of the United States has determined that the tomato is for legal and commercial purposes both a fruit and a vegetable. So we can legally refer to tomato juice as 'vegetable' juice.
  • Candice, General Foods

EER diagram showing Multiple inheritance

3.4.15. EER to Relational Mapping

  • Initially following 7 ER stages
  • Stage 8
  • 4 different options
    • Optimal solution based on problem
  • Let C be superclass, S1..m subclasses

3.4.16. Stage 8

  • Create relation for C, and relations for S1..m each with a foreign key to C (primary key)
  • Create relations for S1..m each including all attributes of C and its primary key

3.4.17. Stage 8

  • Create a single relation including all attributes of C ∪ S1..m and a type/discriminating attribute
    • only for disjoint subclasses
  • Create a single relation as above, but include a boolean type flag for each subclass
    • works for overlapping, and also disjoint