Upload
jewel-stephens
View
214
Download
1
Embed Size (px)
Citation preview
Stephan Karczewski Platteville, 2005/10/07-03 1
Personal
Name: Stephan Karczewski
Professor for Computer Science at the University of Applied Sciences in Darmstadt, Germanyhttp://www.fh-darmstadt.de
Email: [email protected]
Stephan Karczewski Platteville, 2005/10/07-03 2
OO- vs. OR-Databases – What is the better choice?
• Relational Databases are the most used databases in the last 20 years.
• Object orientation in programming languages is the common approach of today´s software development.
• Object oriented (OO) databases come from the OO approach in programming language and give the possibility to make object persistent (since end of the 1980s).
• Object relational databases come from the relational database approach and opens this approach to object orientation (since mid of the 1990s).
Stephan Karczewski Platteville, 2005/10/07-03 3
Object-Orientation in Databases
• Object orientation in database means that• eight rules of object orientation and• five rules of data basesare fullfilled.
What are the rules?
Stephan Karczewski Platteville, 2005/10/07-03 4
Eight rules of object orientation:
1. Complex objects2. Object identity3. Encapsulation of data4. Types and Classes5. Inheritance6. Polymorphism7. Completeness8. Extensibility
Five rules of databases:
1. Persistence2. Large databases3. Multi user operation4. Recovery5. Ad hoc query
Object-Orientation in Databases
Stephan Karczewski Platteville, 2005/10/07-03 5
Object-Orientation in Databases
• Some of the OO rules (e.g. encapsulation) don´t fit to the rules of databases (e.g. ad hoc query).
• Compromises are needed.
The most important of the rules will explained with the next slides.
Stephan Karczewski Platteville, 2005/10/07-03 6
Complex objects:
In relational databases all attributes have to be in first normal form.
That means: each attribute has to be atomar.
The object orientation allows attributes which are • Tuples or• Lists or• Sets.
They don´t fullfil the first normal form.
Object-Orientation in Databases
Stephan Karczewski Platteville, 2005/10/07-03 7
Object identifier (example)
OID ArtId Name Prize
267 CB12 Contra bassoon 18.257087 BT38 Bach trumpet 4.802014 K6456 B89 Bassoon 14.980399 QB29 Quart bassoon 6.493046 flugelhorn120 T46 trumpet 5.490904119 JZ94 Jazz trumpet 6.793
OID is the system key (not changeable). artId is the user definedkey. There are objects without user defined key but not without OID.
Stephan Karczewski Platteville, 2005/10/07-03 8
Encapsulation of data:
One important characteristic of object orientation is that theattributes are encapsulated by the methods.
If a value of an attribute has to be changed, an object must send amessage to the object and only if a method matches this messageThe value will be changed.
In databases there is a ad-hoc query needed so that the user canmake queries to the data direct (with SQL). This is a contradictionto the idea of object orientation.
Object-Orientation in Databases
Stephan Karczewski Platteville, 2005/10/07-03 9
Encapsulation (example)
Tenorsax = Tenor-SaxophonBassoon = Fagott
259-693Tenorsax
5.035
read price
changeprice
buildlist
...711-214Bassoon14.980
read price
changeprice
buildlist
...
attributes
methods
Stephan Karczewski Platteville, 2005/10/07-03 10
Types and Classes:
If a database is object oriented it needs the possibility to definetypes and classes.
Types are usefull to define complex structures.
Classes are usefull to define one schema for similar objects. Remind: In relational databases a table scheme will be used todefine a scheme for similar tuples (rows) in the table.
Object-Orientation in Databases
Stephan Karczewski Platteville, 2005/10/07-03 11
Types and Classes (example)
Object types will defined as classes (in the OOdatabase Fast Objects (former POET)
The used language is related to C++
attributes
methods
ConstructorDestructor
class
DDL from Fast Objects
Stephan Karczewski Platteville, 2005/10/07-03 12
Inheritance:
Inheritance can be used if an hierarchy of classes exist.
One class can inherit attributes and methods from another when itis a specialist of the other class.
This characteristic is helpful because methods don´t have to bedefined more than once in a class from which others inherit.
Object-Orientation in Databases
Stephan Karczewski Platteville, 2005/10/07-03 13
Simple inheritance
InstrumentarticleIdnameprizereadPricechangePricebuildList
WindInstrument...buildList
WoodWindInstrument Order: Increase price of bassoon 711-214 for 8%
Search for attribute priceand method changePrice in class WindInstrument
notfound
Search for attribute priceand method changePrice in higher class WindInstrument
found
Simple means: The search process fromhierarchy to hierarchy is definite.
Stephan Karczewski Platteville, 2005/10/07-03 14
Multiple inheritance
WindInstrument
HarmonicaInstrument
KeyboardInstrument
1. Order: number of keys; will be found in KeybordInstrument
2. Order: pressure of wind: will be found in WindInstrument
1. 2.
Stephan Karczewski Platteville, 2005/10/07-03 15
Inheritance (example)
Specialisation (example):trader (Händler), forwarding(Spediteur), customer (Kunde),organizer (Veranstalter) arespecial business partner
Stephan Karczewski Platteville, 2005/10/07-03 16
Different Inheritance structures
• disjoint and complete
• disjoint and incomplete
• overlapping and complete
• overlapping and incomplete
Stephan Karczewski Platteville, 2005/10/07-03 17
Instrument
WindInstrument PercussionInstrument
Disjoint and Complete
WindInstrument
PercussionInstrument
There are no instruments which areneither Wind- nor PercussionInstrument.
There are no instruments which aresimultaneously Wind- and Percussion-Instrument
{disjoint, complete}
abstract class
Stephan Karczewski Platteville, 2005/10/07-03 18
Instrument
WindInstrument PercussionInstrument
Disjoint and Incomplete
WindInstrument
PercussionInstrument
There are some instruments which areneither Wind- nor PercussionInstrument.
There are no instruments which aresimultaneously Wind- and Percussion-Instrument
{disjoint, incomplete}
Normal (not abstract) class
Stephan Karczewski Platteville, 2005/10/07-03 19
WindInstrument KeyboardInstrument
Overlapping and Complete
WindInstrument KeyboardInstrument
There are no instruments which areneither Wind- nor KeyboardInstrument.
There are some instruments which aresimultaneously Wind- and Keyboard-Instrument.
{overlapping, complete}
abstract classInstrument
Stephan Karczewski Platteville, 2005/10/07-03 20
WindInstrument KeyboardInstrument
Overlapping and Incomplete
There are some instruments which areneither Wind- nor KeyboardInstrument.
There are some instruments which aresimultaneously Wind- and Keyboard-Instrument
{overlapping, incomplete}
Normal (not abstract) class
WindInstrument KeyboardInstrument
Instrument
Stephan Karczewski Platteville, 2005/10/07-03 21
Overlapping and Incomplete
Overlapping can be solved by defining a new class. This class contains all elements of the former intersection set.
WindInstrument
KeyboardInstrument
AccordionInstrument
WindInstrument KeyboardInstrument
{disjoint, complete}
AccordionInstrument
Instrument
Stephan Karczewski Platteville, 2005/10/07-03 22
Polymorphism and Overriding (example)
InstrumentarticleIdnameprizereadPricechangePricebuildList
WindInstrument...buildList
WoodWindInstrument
Overriding means: There are same named methods in a hierarchy. BuildListin WindInstruments overrides buildList inInstrument.The method buildList is polymorph.
Order from WoodWindInstrument: Give a list of Instruments
The special method for windInstruments will be used.
Order from Instrument: Give a list of Instruments
The method for Instruments will be used.
Stephan Karczewski Platteville, 2005/10/07-03 23
Association (example):
Set of references to markets (Markt) (*)Reference to a promoter (Veranstalter) (1)
Transformation of OO components
Stephan Karczewski Platteville, 2005/10/07-03 24
Association with association class:
Set of references to offer (Angebot) (*)Set of references to offer (Angebot) (*)
Reference to product (1)Reference to market (1)
Transformation of OO components
Stephan Karczewski Platteville, 2005/10/07-03 25
Disadvantage of OO Databases
OODBS made a revolution in the database world.
The systems have not been compatible to the used relational systems.
Many companies didn´t use the OODBS because the didn´t like the idea to migrate the mass of data they had.
Today OODBS are used only in a niche of the database world.
Stephan Karczewski Platteville, 2005/10/07-03 26
Advantage of OR Databases
ORDBS made an evolution in the database world.
The systems are upwords compatible to the used relational systems.
Today ORDBS come in use more and more because the user does not need to migrate the old data.
In the following slides there will be shown some examples which enlarge the possibilities of relational databases with object oriented features.
Stephan Karczewski Platteville, 2005/10/07-03 27
Complex objects in ORDBS (Oracle)
product is a structured type
participants is a table of products
Market is a table with a table (participants) in it
Stephan Karczewski Platteville, 2005/10/07-03 28
Structure of the defined ORDBS table
row
One row contains two (!) paticipants.
Stephan Karczewski Platteville, 2005/10/07-03 29
Insert command (ORSQL, Oracle)
A constructor will used to define a table defined attribute.
Stephan Karczewski Platteville, 2005/10/07-03 30
Update command (ORSQL, Oracle)
A subselect is used to select all paticipants which are in a sub table of the market.
An alias is used (and needed) to update all sub rows.
Stephan Karczewski Platteville, 2005/10/07-03 31
Select command (ORSQL, Oracle)
The name, position and category of the market and
the number of paticipants (in a subselect)
will be selected in this statement.
Stephan Karczewski Platteville, 2005/10/07-03 32
Select command (ORSQL, Oracle)
The number and position of all markets will be selected,in which more than 2 participants (as subselect) are.