ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website:...

34
ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: www.cse.yorku.ca/~gordon/it ec3220S07 Office: CSEB3020

Transcript of ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website:...

Page 1: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

ITEC 3220AUsing and Designing Database Systems

Instructor: Gordon TurpinCourse Website: www.cse.yorku.ca/~gordon/itec3220S07 Office: CSEB3020

Page 2: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

Appendix G

Object-Oriented Database

Page 3: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

3

Object Orientation

• Object Orientation – Set of design and development

principles– Based on autonomous computer

structures known as objects

• OO Contribution areas– Programming Languages– Graphical User Interfaces– Databases– Design – Operating Systems

Page 4: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

4

• Concepts stem from object-oriented programming languages Ada, ALGOL, LISP, SIMULA

• OOPLs goals– Easy-to-use development environment– Powerful modeling tools for development– Decrease in development time– Make reusable code

• OO Attributes– Data set not passive– Data and procedures bound together– Objects can act on self

Evolution of OO Concepts

Page 5: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

5

OO Concepts: Objects

• Abstract representation of a real-world entity – Unique identity– Embedded properties– Ability to interact with other objects

and self• OID

– Unique to that object– Assigned by system at moment of

object’s creation – Cannot be changed under any

circumstances– Can be deleted only if the object is

deleted– Can never be reused

Page 6: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

6

Attributes (Instance Variables)

• Attributes:

– Known as instance variables in OO environment

• Domain:

– Logically groups and describes the set of all possible values that an attribute can have

Page 7: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

7

Object State

• Set of values that object’s attributes have at a given time

• Can vary, although its OID remains the same

• To change the object’s state, change the values of the object’s attributes

• To change the object’s attribute values, send a message to the object

– Message will invoke a method

Page 8: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

8

Messages and Methods

• Method: – Code that performs a specific

operation on object’s data– Protects data from direct and

unauthorized access by other objects

– Used to change the object’s attribute values or to return the value of selected object attributes

– Represent real-world actions

Page 9: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

9

Classes

• Collection of similar objects with shared structure (attributes) and behavior (methods)

• Class instance or object instance

– Each object in a class

Page 10: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

10

Protocol

• An object’s public aspect

• How it is known by other objects as well as end users

• Other objects communicate with the student object using any of these methods

Page 11: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

11

Object Characteristics

Page 12: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

12

Class Hierarchy

• Superclass • Subclass• Class lattice

Page 13: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

13

Inheritance

• Ability of object to inherit the data structure and behavior of classes above it

• Single inheritance– Class has one immediate

superclass

Page 14: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

14

Inheritance (Cont’d.)

• Multiple– Class has more than one

immediate superclass

Page 15: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

15

Method Overriding

• Method redefined at subclass level

Page 16: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

16

Polymorphism

• Allows different objects to respond to same message in different ways

Page 17: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

17

Abstract Data Types (ADT)

• Describes a set of similar objects• Differs from conventional data

types– Operations are user-defined– Uses encapsulation

• Definitions needed for creation– Name– Data representation– Abstract data type operations and

constraints

Page 18: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

18

Object Classification

• Simple – Only single-valued attributes – No attributes refer to other object

• Composite – At least one multivalued attribute – No attributes refer to other object

• Compound – At least one attribute that references other

object• Hybrid

– Repeating group of attributes– At least one refers to other object

• Associative object

Page 19: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

19

OO vs. E-R Model Components

Page 20: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

20

Class-Subclass Relationship

Page 21: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

21

• Attribute-Class Link• Object’s attribute references

another object• Relationship Representation

– Related classes enclosed in boxes – Double line on right side indicates

mandatory– Connectivity indicated by labeling

each box• 1:M • M:N • M:N with an Intersection Class

Interobject Relationships

Page 22: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

22

1:1 and 1:M Relationships

Page 23: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

23

Employee-Dependent Relationship

Page 24: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

24

Representing the M:N Relationship

Page 25: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

25

Representing the M:N Relationship with Associated

Attributes

Page 26: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

26

Representing the M:N Relationship with Intersection

Class

Page 27: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

27

• Late binding– Data type of attribute not known

until runtime– Allows different instances of

same class to contain different data types for same attribute

• Early binding– Allows database to check data

type at compilation or definition time

Late and Early Binding

Page 28: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

28

• Object, Entity, and Tuple– OODM object has behavior, inheritance, and

encapsulation – OO modeling more natural

• Class, Entity Set, and Table– Class allows description of data and behavior– Class allows abstract data types

• Encapsulation and Inheritance– Object inherits properties of superclasses– Encapsulation hides data representation and

method

OODM vs. E-R Data Models

Page 29: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

29

• Object ID– Not supported in

relational models

• Relationships– OODM

• Interclass references • Class hierarchy

inheritance

– Relational models • Value-based

approach

OODM vs. E-R Data Models (Cont’d)

• Access– Relational

models • SQL

– OODM• Navigational • Set-oriented

access

Page 30: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

30

Example

Assume the following business rules:• A course contains many sections, but each

section has only one course• A section is taught by one professor, but each

professor may teach one or more different sections of one or more course

• A section may contain many students, and each student is enrolled in many sections, but each section belongs to a different course. (Students my take many courses, but they cannot take many sections of the same course.)

• Each section is taught in one room, but each room may be used to teach several different sections of one or more courses

• A professor advises many students, but a student has only one advisor

Page 31: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

31

Example (Cont’d)

•Identify and describe the main classes of objects

•Modify your description in part 1 to include the use of abstract types such as Name, DOB, and Address

•Create the conceptual OO representations

Page 32: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

32

More Example

Using intersection class to represent the following relationship

Page 33: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

33

OO Design Example

Design OO conceptual representations for an engineering company, using the following requirements:•A customer has a unique customer identifier. Other important attributes of each customer include name and address. They can request any number of work orders from the company.•The company maintains a list of materials. The data about materials include a unique material identifier, a name and cost.•A work order has a unique work order number, a creation date, a completion date, a work address and a set of (one or more) tasks. In addition, each work order has one optional supervising employee. Each employee has a unique number assigned by the company. Other important attributes of each employee include name and skill. •Each work order also has a collection of materials. The same material can be used by any number of work orders. Material requirement includes material quantity.•Each task has a unique task identifier, a task name, an hourly rate and estimated hours. Tasks are standardized across work orders so that the same task may be performed on many work orders. We have to keep record of actual hours of each task on a work order.

Page 34: ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: gordon/itec3220S07 Office: CSEB3020.

34

OO Influences on Relational Model

• Extensibility of new user-defined (abstract) data types

• Complex objects• Inheritance• Procedure calls (rules or

triggers)• System-generated identifiers

(OID surrogates)