Title: Object Oriented Modelling Super Types
1Object Oriented ModellingSuper Types Sub Types
- HIIB62
- Databases and Data Modelling
- Contributions by Arthur Adamopoulos, Hossein S.
Zadeh, Ian Searle and Ian Storey
2What is Object Oriented?
- The object-oriented approach models a system as a
collection of interacting objects - that the
objects in a computer system, like the objects in
the world around us, are viewed as things.
3What is Object Oriented?
- These things (or objects) have certain features,
or attributes, and they can exhibit certain
behaviours. Similar objects in a system can be
grouped and classified as a specific type of
thing (or class).
4What is Object Oriented?
- Another important concept is that objects
interact, that one object can tell another object
to do something via a message.
5What is an Object?
- An object is an entity that has state, behaviour,
and identity. - State includes an objects properties (attributes
and relationships) and the values those
properties have. - The objects under discussion could be
electronic objects in a computer system or real
objects found in a real human system.
6What is an Object?
- The following are all objects that each have a
type, and encapsulate characteristics and
behaviour
7UMLUnified Modelling Language
- The Unified Modelling Language (UML) is a
language for specifying, visualising and
constructing the artefacts of software systems,
as well as for business modelling. - UML provide notation for graphically depicting
object-oriented analysis and design models. It
allows for - Specification of system requirements.
- Capture of design decisions.
- The promotion of communication among the key
persons involved in system development.
8UML Models
- Class diagrams, which show the static structure
of data, and the operations that act on the data. - Use cases, which represent the functional
requirements, or the what of the system. - State diagrams, which represent dynamic models of
how objects change their states in response to
events. - Sequence diagrams, which represent dynamic models
of interactions (message flow) between objects.
9What is a Class?
- A collection of like objects.
- A template for defining new object instances.
- The behaviours reside in the class.
- Behaviour is implemented by methods (which can
also be called services).
Class name
Student name dateOfBirth address phone calc-age()
register-for(course)
Course courseCode courseTitle creditHours enrolmen
t()
List of attributes
List of methods
10Relationships
- Relationships as defined in E-R modelling also
apply to OO modelling. - UML represents relationship with a line, just as
in E-R diagrams. - UML, however, divides relationships into a number
of different categories, each with distinct
symbols at the ends of the lines.
11Association
- An association is a meaningful connection between
two classes, just as in E-R modelling. - Associations are said to be loose
relationships, in that if the relationship was
broken, none of the objects would be deleted
each can continue to exist in its own right.
12Association
Student
Course
StudentNo Surname Given
CrsCode Name
1
13Cardinality / Multiplicity
- one-to-one
- One-to-many
- Many-to-Many
- One-to-three
1
1
1
3
1
14Aggregation / Composition
- An aggregation is a stronger form of
relationship. - Aggregations are usually termed has a or part
of relationships. - One of the objects is said to belong to the
other. If the main object is deleted then the
related objects would also be deleted.
15Aggregation / Composition
Window
Button
Title Position
Label Position
16Inheritance Introduction
- Assume we are designing a system for a university
library. - We may define the following classes
- Student
- Staff
- Book
- Loan
17Inheritance Introduction
Student
Staff
BorrowerNo Surname Given StudentNo CrsCode
BorrowerNo Surname Given StaffNo Extension
setBorrowerNo() setSurname() setGiven() setStudent
No() setCrsCode()
setBorrowerNo() setSurname() setGiven() setStaffNo
() setExtension()
18Inheritance Introduction
- You may notice that the Student and Staff classes
have some things in common - Common fields
- Common methods
- We can take these similarities and put them into
a higher level class (Borrower). - We can then make the Student and Staff classes be
sub-classes of this higher class.
19Borrower
SuperClass
BorrowerNo Surname Given
setBorrowerNo() setSurname() setGiven()
SubClasses
Student
Staff
StudentNo CrsCode
StaffNo Extension
setStudentNo() setCrsCode()
setStaffNo() setExtension()
20Inheritance
- Sub-class inherits everything from super-class.
- An object of type Student is also an object of
type Borrower. - It inherits all fields and methods defined in
Borrower. - Can be used any place a Borrower object can be
used.
21Enhanced ER Model (EER) has Super and Sub Types
- The ER model has been enhanced by various people
to include inheritance. - Concepts have simply been borrowed from the OO
model but drawn differently. - In practice if you wanted to create a model
involving inheritance you would probably go
directly to an OO model.
22EER Model Super/Sub Types
23CASE Tools
24OBJECT/RELATIONALMAPPING
25Mapping Classes to Tables
- We can use tables to store the values of objects.
Roughly, each object is represented by a row
(record). - In the same way that we map an E-R model to the
relational model, we need to create a mapping
from the class model to the relational/SQL model. - For the most part this is identical to mapping an
E-R model.
26Mapping Classes
- For the most part, a class in the class model
will be mapped to a table in the relational model
(see handling inheritance later). - A single record in the table will represent the
contents of one object. - However, as in dealing with E-R models, every
table in the relational model does not
necessarily map back to a class.
27Mapping Attributes
- Native type attributes (ie. Numbers, text, dates
etc) are simply fields in the table. - Some native types may need translation (eg.
Boolean may be stored as Y/N char) - Attributes that reference other objects are
actually storing relationships as per an E-R
model see next slide.
28Mapping Relationships
- A relationship is implemented as a foreign key
just like with an E-R model. - 1-1 Relationship foreign key either side
- 1-M Relationship foreign key on many side
- In Java, a M-M relationship would usually be
constructed with a hash table, so the entries in
the hash table need to be mapped out to their own
table.
29Mapping Inheritance
- Most relational databases do not support
inheritance (some actually do). - There are three different options to map
inherited classes - Keep All Levels
- Roll Up
- Roll Down
- This choice is made for every individual
inheritance relationship.
30Sample classes
Borrower
BorrowerNo Surname Given
Student
StudentNo CrsCode
31Keep All Levels
- This is simply representing every class in the
inheritance hierarchy as a table. - This means, however, that one physical instance
object of a sub-class will be saved across
multiple rows in multiple tables. - A common key may need to be introduced to
maintain the link between the super and sub-class
tables so objects can be re-built from their
parts.
32Keep All Levels
- Borrower Student Staff
- BorrNo BorrNo BorrNo
- Surname StudentNo StaffNo
- Given CrsCode Extension
33Roll Up
- All the attributes from the sub-class are rolled
up into the super-class. - One table is then used to represent the combined
attributes of both the super and sub-class
objects. - An extra field is usually needed to flag which
type of object the row represents (ie. Which
sub-class does it belong to).
34Roll Up
- Borrower
- BorrNo
- Surname
- Given
- BorrType
- StudentNo
- CrsCode
- StaffNo
- Extension
35Roll Down
- All the attributes from the super-class are
rolled down into each sub-class. - A table is then used to represent each sub-class,
with no table for the super-class. - The attributes from the super-class are, in
effect, repeated in each sub-class table.
36Roll Down
- Student Staff
- BorrNo BorrNo
- Surname Surname
- Given Given
- StudentNo StaffNo
- CrsCode Extension