Object Oriented Data Models L19. Topics Objects in PHP –Generalisation –Polymorphism –Reusable classes –Objects and Databases Next week –Data modelling.

Slides:



Advertisements
Similar presentations
Three-Step Database Design
Advertisements

Chapter 10: Designing Databases
Chapter 14 (Web): Object-Oriented Data Modeling
Organizing Data & Information
ISD3 Chris Wallace Next 6 Weeks Extended Relational Model Object Orientation Matching systems 3 tier architecture Technology.
Geographic Information Systems
Object-Oriented Databases
Chapter 11 Data Management Layer Design
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 1.
OO - Lecture 4 Tutorial Review Associations Inheritance of Functions Polymorphism.
Object orientation - 3 Review of Tutorial 2 Encapsulation Reusable Types Inheritance.
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 18 Object Database Management Systems.
RIZWAN REHMAN, CCS, DU. Advantages of ORDBMSs  The main advantages of extending the relational data model come from reuse and sharing.  Reuse comes.
Chapter 14: Object-Oriented Data Modeling
EER vs. UML Terminology EER Diagram Entity Type Entity Attribute
Object Oriented Software Development
Database Management System Lecture 3 Models of Database Management Systems.
Systems analysis and design, 6th edition Dennis, wixom, and roth
11 1 Object oriented DB (not in book) Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Learning objectives: What.
Module Title? DBMS Introduction to Database Management System.
G041: Lecture 07 Business ICT Systems Mr C Johnston ICT Teacher
1 CS 430 Database Theory Winter 2005 Lecture 1: Introduction.
Database Management Exploring the Territory. Database vs Flat Files Flat Files –Characters-fields-records-files Files are not designed to work together.
1 INTRODUCTION TO DATABASE MANAGEMENT SYSTEM L E C T U R E
Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications.
Object-Oriented Database Management Systems (ODBMS)
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
Computer Science 101 Database Concepts. Database Collection of related data Models real world “universe” Reflects changes Specific purposes and audience.
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
1 CS 430 Database Theory Winter 2005 Lecture 17: Objects, XML, and DBMSs.
SQL, Data Storage Technologies, and Web-Data Integration Week 2.
Unit 6 Data Storage Design. Key Concepts 1. Database overview 2. SQL review 3. Designing fields 4. Denormalization 5. File organization 6. Object-relational.
Object Persistence Design Chapter 13. Key Definitions Object persistence involves the selection of a storage format and optimization for performance.
Slide 1 Object Persistence Design Chapter 13 Alan Dennis, Barbara Wixom, and David Tegarden John Wiley & Sons, Inc. Slides by Fred Niederman Edited by.
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
CET203 SOFTWARE DEVELOPMENT Session 1A Revision of Classes.
Chapter 12: Designing Databases
Chapter 18 Object Database Management Systems. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Motivation for object.
CHAPTER 13 (ONLINE): OBJECT-ORIENTED DATA MODELING © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database Management 11 th Edition.
1 © Prentice Hall, 2002 Chapter 14: Object-Oriented Data Modeling Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B. Prescott, Fred R.
© 2011 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 13 (Online): Object-Oriented Data Modeling Modern Database Management 10 th Edition.
Object-Oriented Data Modeling
SQL SeQueL -Structured Query Language SQL SQL better support for Algebraic operations SQL Post-Relational row and column types,
Creating and Maintaining Geographic Databases. Outline Definitions Characteristics of DBMS Types of database Relational model SQL Spatial databases.
1 CSC/ECE 517 Fall 2010 Lec. 3 Overview of Eclipse Lectures Lecture 2 “Lecture 0” Lecture 3 1.Overview 2.Installing and Running 3.Building and Running.
Guofeng Cao CyberInfrastructure and Geospatial Information Laboratory Department of Geography National Center for Supercomputing Applications (NCSA) University.
ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: Office: CSEB3020.
1 CS 430 Database Theory Winter 2005 Lecture 14: Additional SQL Topics.
Chapter 2 Object-Relational DBMSs Chapter 28 in Textbook.
Intro to GIS | Summer 2012 Attribute Tables – Part 1.
9-1 © Prentice Hall, 2007 Topic 9: Physical Database Design Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich,
March 1, 2004CS WPI1 CS 509 Design of Software Systems Lecture #6 Monday, March 1, 2004.
CET203 SOFTWARE DEVELOPMENT Session 2A Inheritance (programming in C#)
Chapter 18 Object Database Management Systems. Outline Motivation for object database management Object-oriented principles Architectures for object database.
1 10 Systems Analysis and Design in a Changing World, 2 nd Edition, Satzinger, Jackson, & Burd Chapter 10 Designing Databases.
Chapter 1: Introduction. 1.2 Database Management System (DBMS) DBMS contains information about a particular enterprise Collection of interrelated data.
Faeez, Franz & Syamim.   Database – collection of persistent data  Database Management System (DBMS) – software system that supports creation, population,
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
OODBMS and ORDBMS. Background Object-oriented software, based on the principles of user-defined datatypes, along with inheritance and polymorphism, is.
Geographic Information Systems GIS Data Databases.
Modeling Constraints Extracting constraints is what modeling is all about. But how do we express them? Examples: Keys: social security number uniquely.
Object-Oriented Database Management System (ODBMS)
Object-Relational DBMSs
Phil Tayco Slide version 1.0 Created Nov. 26, 2017
Tools for Memory: Database Management Systems
Lec 3: Object-Oriented Data Modeling
Database Design: Relational Model
Object-Oriented Databases
Terms: Data: Database: Database Management System: INTRODUCTION
Presentation transcript:

Object Oriented Data Models L19

Topics Objects in PHP –Generalisation –Polymorphism –Reusable classes –Objects and Databases Next week –Data modelling patterns - Fowler

Tenets of the Relational model Data in 1NF relations - no repeated fields Data in 3NF relations - no redundant data Field values drawn from small range of supplied data types Relationships require join operation Basic CRUD operations Passive - changes only when UPDATEd Balanced implementation- updates and read

Common applications Core business processing –Accounting systems –Order processing –Stock control Administrative systems –student records –admissions –bookings

Tricky application domains Design systems - CAD, CAM, CASE Text searching - search engine Multi-media, hyper-media systems - images, video, audio, complex networks Spatial data - Geographic Information Systems Decision support systems - analysis of large body of ‘static’ data Real-time active systems - air-traffic control

Complex entities Electronic components in a Computer Aided Design (CAD) system Mechanical components in a Computer Aided Manufacturing (CAM) system Software requirements, specifications and components in a CASE environment Multi-media documents - text, images and sounds in multimedia document managers Spatial or geographic data, such as geometric figures and maps in a Geographic Information System (GIS)

Objects and entities Can view as extension of Entity- Relationship modelling Entity type = = class – roughly = table definition – part of schema Entity instance = = object –roughly= row –part of factbase –+ OID Object Identifier to ensure uniqueness –+ type ref so Object is not tied to table

Class Defines the attributes of the objects of that kind –attributes may be basic types - strings, numbers, dates array or object encapsulated in object references to other objects –methods constructor - to create a new object accessors - to access attributes, compute derived data modifiers - to change attributes

A PHP class <?php class emp { var $name, $sal, $comm; function emp($n,$s,$c) { $this->name=$n; $this->sal=$s; $this->comm=$c; } function yearsal() { return $this->sal * 12 + $this->comm; } $x = new emp('Jones', 200, 5); print_r($x); $xsal = $x->yearsal(); print ("$x->name earns $xsal per annum");

PHP v Java Object orientation in PHP4 is rather minimal by comparison with Java PHP variables are untyped All variables publicly accessible PHP $this === Java self (and no default) PHP -> === Java.

Inheritance Salaried staff and contract staff are exclusive categories, but they overlap in specification – all are ‘employees’ and share some common characteristics employee Salaried staff contractor Is a Common attributes Common methods Local attributes Local methods (new or replacement)

Generalisation and Specialisation class employee { var $name; function yearsal() { return false; } function initial() { return substr($this->name,0,1); } class salaried extends employee { var $sal, $comm; function salaried($n,$s,$c) { $this->name=$n; $this->sal=$s; $this->comm=$c; } function yearsal() { return $this->sal * 12 + $this->comm; } class contractor extends employee { var $rate, $days; function contractor($n,$r,$d) { $this->name=$n; $this->rate=$r; $this->days=$d; } function yearsal() { return $this->rate * $this->days; }

Creating and using Objects $x = new salaried ('Fred', 100, 99); $xsal= $x->yearsal(); $i = $x->initial(); print ("$i $x->name earns $xsal per annum "); $y = new contractor('Joe', 10, 300); $ysal= $y->yearsal(); print ("$y->name earns $ysal per annum "); Output is F Fred earns 1299 per annum Joe earns 3000 per annum

Polymorphism Many shapes An ‘employee’ object may be really a ‘salaried’ object or a ‘contractor’ object Sometimes we want to treat as an instance of the generalisation (employee), sometimes as the special case (salaried or contractor)

Power of Polymorphism class company { var $name, $staff; function company($n) { $this->name = $n; } function employ($s) { $this->staff[] = $s; } function yearsal() { $tot = 0; foreach($this->staff as $person) { $tot = $tot + $person->yearsal(); } return $tot; } $c = new company("University of the West of England"); $c->employ($x); $c->employ($y); $csal= $c->yearsal(); print ("$c->name pays $csal per annum "); University of the West of England pays 4299 per annum

How does it work? In the calculation loop, each employee is accessed in turn. When the function annualsal() is called, it is the version appropriate to the objects base class which is used, so the appropriate calculation is performed.

Object References In a relational model, rows are related by shared values –the deptno in an Emp row = the deptno in a Dept row Objects have a system-generated unique identifier (across all objects, not just the rows in a single table like an auto_increment column) References can be stored as an attribute of another object

Emps and Depts class dept { var $name, $location, $manager; function dept($n, $l, $m) { $this->name = $n; $this->location = $l; $this->manager = $m; } $d = new dept("Accounting","Swindon", & $x); // print("Department $d->name is managed by $d->manager->name "); // cant chain in PHP 4.3 $boss = $d->manager; print("Department $d->name is managed by $boss->name "); Department Accounting is managed by Fred

Reflection Reflection refers to the ability of a program to find out about itself For example, there are functions to: –Get the class of an object –Get the superclass of an object –Get the names of the class methods (functions) –Get the names of the class variables Classes could be called ‘self-describing’

Reflection code $class= get_class($x); $super = get_parent_class($x); print ("$x->name is a $class ($super) "); $class= get_class($y); $super = get_parent_class($y); print ("$y->name is a $class ($super) "); Fred is a salaried (employee) Joe is a contractor (employee)

User-defined types Codd’s relational model has ‘domains’ – commercial RDBMS and programming languages provide only standard types with standard functions (integer, string, date) Applications require –restrictions on standard types e.g. restricted values - can sometimes use Constraints to enforce –types defined by several values bound together eg international currency requires amount and currency code –functions which operate on these types eg to convert between 2 international currencies

0 0 < 1Calm Light air Light breeze Gentle breeze Moderate breeze Fresh breeze Strong breeze Near gale Gale Strong gale Storm Violent storm 1212>= 64Hurricane Beaufort Scale

Degree classification fail pass rd st

Relational DB using a theta join Grade table class min max fail034 pass3539 3rd4049 Student table name mark fred38 sally57 Getting the class select name, class from student, grade where mark between min and max;

Common problems Converting a wind speed in Beaufort scale –25 knots is Force 6 Converting average mark on degree to an Honours classification –56 marks is a 2.1

fail pass 3rd st Honours Grades topmark mark class classInterval class classlist classification name

Classification name : varchar getClass(mark : number) : string classInterval topMark : number class : String 1..*

Reusable Types This Classification type is OK for Honours grades But can we use it for Beaufort scale too?. Three approaches –Use Classification type (but the names will all be wrong) –Create another similar type with ‘wind’ name (wasted work) –Generalise the Classification type with more neutral names (can be hard to find good names and not so readable) We can generalise the names –classInterval > range –topmark > limit –class > value –classification > rangeFunction –getClass() > getValue()

rangeFunction name : string getValue(val : number) : string range limit : number value : String 1..*

class range { var $limit, $value; function range($l,$v) { $this->limit = $l; $this->value = $v; } class rangeFunction { var $name, $ranges; function rangeFunction($n) { $this->name= $n; } function addRange($r) { $this->ranges[]=$r; } function getValue($val) { foreach($this->ranges as $r ) { if ($val limit) { return $r->value; } return false; }

$pr = new rangeFunction("Prices"); $r = new range(9, 9); $pr->addRange ($r); $r = new range(19, 7); $pr->addRange ($r); $r = new range(99, 5); $pr->addRange ($r); $r = new range( , 4); $pr->addRange ($r); //print_r($pr); for($i=0;$i<200;$i+=5) { $price = $pr->getValue($i); $cost = $i * $price; print("price for $i at £$price is £$cost "); } price for 0 at £9 is £0 price for 5 at £9 is £45 price for 10 at £7 is £70 price for 15 at £7 is £105 price for 20 at £5 is £100 price for 25 at £5 is £125

Where can we use this class? Honours grades Beaufort scale Salary grades Discount rates for multiple purchase Tax rate bands...

Objects and Databases Objects don’t fit well into a RDBMS –How many tables would the Beaufort Scale require? –Some RDBMS have stored procedures but not integrated with data Object-Relational databases (e.g. Oracle 9i) try to bridge the gap by adding types, methods, inheritance, references but not popular J2EE and.NET do the mapping to and from Objects in the Middle tier.

Row to Object mapping class person { var $usercode,$familyname, $givenname, $job, $dept, $ext, $homephone, $room, $fullname; var $dblink; function person($db) { $this->dblink = $db; } function get($username) { $res = mysql_query("select * from staff where username='$username'",$this->dblink); if (!$e = mysql_fetch_object($res) ) return false; $this->username = $e->username; $this->givenname = $e->givenname; $this->familyname = $e->familyname; $this->ext = $e->ext; $this->homephone =''; $this->room = $e->room; $this->fullname = $this->givenname. ' '. $this->familyname; } function put() { $res = mysql_query("update staff set givenname='$this->givenname', familyname = '$this->familyname', ext= '$this->ext', room= '$this->room' where username='$this->username'", $this->dblink); return $res; } function show() { print(" $this->fullname is in Room $this->room on Ext. $this->ext "); }

Testing $x = new person( $db); $x->get('CW'); $x->show(); $x->ext= $x->ext+1; $x->put($db); $y = new person($db); $y->get('CW'); $y->show(); Chris Wallace is in Room 3P14 on Ext Chris Wallace is in Room 3P14 on Ext

Tutorial work Exercises –Update the Rose model to show the OO features –A new subtype for Volunteers who get paid a flat annual fee –Salgrade table as an object in PHP