l14 l15 oo dbms

48
Rushdi Shams, Dept of CSE, KU ET Database Systems Database Systems Object Oriented Database Object Oriented Database Management Systems Management Systems Version 1.0 Version 1.0

Upload: rushdi-shams

Post on 19-Jan-2015

95 views

Category:

Technology


6 download

DESCRIPTION

 

TRANSCRIPT

Page 1: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Database Database SystemsSystems

Object Oriented Database Object Oriented Database Management SystemsManagement Systems

Version 1.0Version 1.0

Page 2: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Object- TheoryObject- Theory

An object is a package of data and An object is a package of data and procedures.procedures.

Data is contained in attributes of an Data is contained in attributes of an objectobject

Procedures are defined in methods Procedures are defined in methods of an objectof an object

Page 3: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Object- TheoryObject- TheoryConcept of ClassConcept of Class

Page 4: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Objects- TheoryObjects- TheoryConcepts of ObjectsConcepts of Objects

Page 5: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Object Types in OracleObject Types in OracleConcept of ClassConcept of Class

Page 6: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Objects in OracleObjects in Oracle

When you create a variable of an When you create a variable of an object type, you create an instance object type, you create an instance of the type and the result is an of the type and the result is an objectobject

An object has the attributes and An object has the attributes and methods defined for its typemethods defined for its type

an object instance is a concrete an object instance is a concrete thing, you can assign values to its thing, you can assign values to its attributes and call its methodsattributes and call its methods

Page 7: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Objects in OracleObjects in Oracle

rushdirushdi person_typ;person_typ;

will create an object named rushdi of will create an object named rushdi of type person_typ.type person_typ.

Page 8: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Question at the stageQuestion at the stage

How the property ENCAPSULATION How the property ENCAPSULATION reflects in OODM?reflects in OODM?

What is the difference between What is the difference between object type and object in Oracle?object type and object in Oracle?

What is the relation between What is the relation between Oracle’s object type and OOP’s Oracle’s object type and OOP’s class?class?

Page 9: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Object Type is a Data Object Type is a Data Type!Type!

Defining an object type does not Defining an object type does not allocate any storageallocate any storage

After they are defined, object types After they are defined, object types can be used in SQL statements in can be used in SQL statements in most of the same places you can use most of the same places you can use types like NUMBER or VARCHAR2types like NUMBER or VARCHAR2

Page 10: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Object Type is a Data Object Type is a Data Type!Type!

Page 11: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Question at the stageQuestion at the stage

““An object type is a data type”- An object type is a data type”- justify the answer.justify the answer.

Page 12: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Object Methods in OracleObject Methods in Oracle

Methods are functions or procedures Methods are functions or procedures that you can declare in an object type that you can declare in an object type definition to implement behavior that definition to implement behavior that you want objects of that type to you want objects of that type to performperform

The general kinds of methods that can The general kinds of methods that can be declared in a type definition are:be declared in a type definition are:

1.1. MemberMember2.2. StaticStatic3.3. ConstructorConstructor

Page 13: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Member MethodsMember Methods

Member methods are the means by which Member methods are the means by which an application gains access to an object an application gains access to an object instance's data instance's data

You define a member method in the object You define a member method in the object type for each operation that you want an type for each operation that you want an object of that type to be able to perform object of that type to be able to perform

Page 14: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Static MethodsStatic Methods

Static methods are invoked on the Static methods are invoked on the object type, not its instances object type, not its instances

You use a static method for You use a static method for operations that are global to the operations that are global to the type and do not need to reference type and do not need to reference the data of a particular object the data of a particular object instance instance

A static method has no SELF A static method has no SELF parameter parameter

Page 15: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Static MethodsStatic Methods

You invoke a static method by using You invoke a static method by using the dot notation to qualify the the dot notation to qualify the method call with the name of the method call with the name of the object type, such as:object type, such as:

type_name.method()type_name.method()

Page 16: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Constructor MethodsConstructor Methods

Every object type has a constructor method Every object type has a constructor method implicitly defined for it by the system implicitly defined for it by the system

A constructor method is a function that A constructor method is a function that returns a new instance of the user-defined returns a new instance of the user-defined type and sets up the values of its attributes type and sets up the values of its attributes

Page 17: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Questions at the StageQuestions at the Stage

What are the three methods that can What are the three methods that can be declared in object type definition?be declared in object type definition?

What is the difference between What is the difference between static method and member method?static method and member method?

What is the speciality about What is the speciality about constructor method?constructor method?

Page 18: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Inheritance- TheoryInheritance- Theory

A type hierarchy is a sort of family A type hierarchy is a sort of family tree of object types tree of object types

It consists of a parent base type, It consists of a parent base type, called a super type called a super type

one or more levels of child object one or more levels of child object types, called subtypes types, called subtypes

Child object types are derived from Child object types are derived from parent object classparent object class

Page 19: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Inheritance- TheoryInheritance- Theory

A subtype becomes a specialized A subtype becomes a specialized version of the parent type by adding version of the parent type by adding new attributes and methods to the new attributes and methods to the set inherited from the parent or by set inherited from the parent or by redefining methods it inherits redefining methods it inherits

Redefining an inherited methods Redefining an inherited methods gives a subtype its own way of gives a subtype its own way of executing the method executing the method

Page 20: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Inheritance- TheoryInheritance- Theory

Page 21: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Inheritance- TheoryInheritance- Theory

Page 22: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

PolymorphismPolymorphism

Add to this that an object instance of Add to this that an object instance of a subtype can generally be a subtype can generally be substituted for an object instance of substituted for an object instance of any of its supertypes in code, and any of its supertypes in code, and you have polymorphism you have polymorphism

Page 23: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Final & Not Final- TypesFinal & Not Final- Types

The definition of an object type The definition of an object type determines whether subtypes can be determines whether subtypes can be derived from that type derived from that type

To permit subtypes, the object type must To permit subtypes, the object type must be defined as not final be defined as not final

Page 24: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Final & Not Final- TypesFinal & Not Final- Types

By default, an object type is declared as By default, an object type is declared as final and subtypes cannot be derived from final and subtypes cannot be derived from it it

You can change a final type to a not final You can change a final type to a not final type and vice versa with an ALTER TYPE type and vice versa with an ALTER TYPE statementstatement

You can alter a type from NOT FINAL to You can alter a type from NOT FINAL to FINAL only if the target type has no FINAL only if the target type has no subtypes subtypes

Page 25: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Final & Not Final- Final & Not Final- MethodsMethods

Methods can also be declared to be Methods can also be declared to be final or not final final or not final

If a method is declared to be final, If a method is declared to be final, subtypes cannot subtypes cannot overrideoverride it by it by providing their own implementation providing their own implementation

Unlike types, methods are not final Unlike types, methods are not final by default and must be explicitly by default and must be explicitly declared to be final declared to be final

Page 26: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Final & Not Final- Final & Not Final- MethodsMethods

Page 27: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Inheritance- OracleInheritance- OracleCreating SubtypeCreating Subtype

Page 28: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Inheritance- OracleInheritance- OracleCreating Subtype of Creating Subtype of

subtypesubtype

Page 29: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Questions at the StageQuestions at the Stage

What are the mechanisms Oracle What are the mechanisms Oracle use to reflect the INHERITANCE of use to reflect the INHERITANCE of object oriented architecture?object oriented architecture?

What is the significance of FINAL What is the significance of FINAL and NOT FINAL?and NOT FINAL?

What is the difference of FINAL and What is the difference of FINAL and NOT FINAL in case of object types NOT FINAL in case of object types and methods?and methods?

Page 30: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Method Overriding- Method Overriding- TheoryTheory

An method is said overriding if the An method is said overriding if the method name is same for all the method name is same for all the objects but the objects define how objects but the objects define how the method works according to their the method works according to their convenience.convenience.

Page 31: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Method Overriding- Method Overriding- OracleOracle

Page 32: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Method Overriding- Method Overriding- OracleOracle

Page 33: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Method Overriding- Method Overriding- OracleOracle

Page 34: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Taking you to the Reality Taking you to the Reality

Page 35: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Taking you to the Reality Taking you to the Reality

You can call the show() function for the You can call the show() function for the supertype and subtypes in the table with supertype and subtypes in the table with the following the following

Page 36: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

& The output & The output

Page 37: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Method Overloading- Method Overloading- TheoryTheory

Giving a type multiple methods with Giving a type multiple methods with the same name is called method the same name is called method overloading overloading

Page 38: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Method Overloading- Method Overloading- OracleOracle

Page 39: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Questions at the StageQuestions at the Stage

What are the difference between What are the difference between method overloading and method method overloading and method overriding?overriding?

How Oracle implements method How Oracle implements method overriding?overriding?

How Oracle implements method How Oracle implements method overloading?overloading?

Page 40: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Map MethodsMap Methods

A map method is an optional kind of A map method is an optional kind of method method

provides a basis for comparing objects provides a basis for comparing objects by mapping object instances to one of by mapping object instances to one of the scalar types DATE, NUMBER, the scalar types DATE, NUMBER, VARCHAR2 or to an ANSI SQL type VARCHAR2 or to an ANSI SQL type such as CHARACTER or REAL such as CHARACTER or REAL

With a map method, you can order With a map method, you can order any number of objects by calling each any number of objects by calling each object's map method once object's map method once

Page 41: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Map MethodsMap Methods

a map method is simply a parameter-a map method is simply a parameter-less member functionless member function

uses the MAP keyworduses the MAP keyword returns one of the datatypes just listed returns one of the datatypes just listed What makes a map method special is What makes a map method special is

that, if an object type defines one, the that, if an object type defines one, the method is called automatically to method is called automatically to evaluate such comparisons as obj_1 > evaluate such comparisons as obj_1 > obj_2 obj_2

Page 42: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Map MethodMap Method

Where obj_1 and obj_2 are two Where obj_1 and obj_2 are two object variables that can be object variables that can be compared using a map method compared using a map method map(), the comparison:map(), the comparison:

obj_1 > obj_2obj_1 > obj_2

is equivalent to:is equivalent to:

obj_1.map() > obj_2.map()obj_1.map() > obj_2.map()

Page 43: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Map MethodMap Method

Page 44: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Order MethodOrder Method

Order methods make direct object-Order methods make direct object-to-object comparisons to-object comparisons

Unlike map methods, they cannot Unlike map methods, they cannot map any number of objects map any number of objects

They simply tell you that the current They simply tell you that the current object is less than, equal to, or object is less than, equal to, or greater than the other object that it greater than the other object that it is being compared to, with respect is being compared to, with respect to the criterion used by the method to the criterion used by the method

Page 45: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Order MethodOrder Method

Page 46: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

Question at the StageQuestion at the Stage

What are the methods used to What are the methods used to compare Oracle objects? Can you compare Oracle objects? Can you give two examples to define them?give two examples to define them?

What are the differences between What are the differences between map method and order method?map method and order method?

Page 47: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

ReferenceReference

Oracle 10g User manual for Object Oracle 10g User manual for Object Oriented Data ModelOriented Data Model

www.wikipedia.orgwww.wikipedia.org

Page 48: L14 l15  oo dbms

Rushdi Shams, Dept of CSE, KUET

AcknowledgementAcknowledgement

Nick Whittaker, Lecturer, University Nick Whittaker, Lecturer, University of Manchester, UKof Manchester, UK