Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory...

43
Challenges of Teaching Challenges of Teaching OO Constructs with OO Constructs with Databases Databases Shahram Ghandeharizadeh Shahram Ghandeharizadeh Database Laboratory Database Laboratory Computer Science Department Computer Science Department University of Southern California University of Southern California
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    230
  • download

    2

Transcript of Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory...

Page 1: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Challenges of Teaching OO Challenges of Teaching OO Constructs with DatabasesConstructs with Databases

Shahram GhandeharizadehShahram Ghandeharizadeh

Database LaboratoryDatabase LaboratoryComputer Science DepartmentComputer Science DepartmentUniversity of Southern CaliforniaUniversity of Southern California

Page 2: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

OutlineOutline

An overview of Introductory course to An overview of Introductory course to databases.databases.

Object-oriented challenges.Object-oriented challenges. Future role of object-oriented Future role of object-oriented

constructs in data intensive constructs in data intensive applications.applications.

Page 3: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Database SystemsDatabase Systems

Used almost on a daily basis for either Used almost on a daily basis for either individual or business use.individual or business use.

Relational database vendors were one Relational database vendors were one of the fastest growing sectors during of the fastest growing sectors during the .COM boom!the .COM boom!

Page 4: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Data ModelsData Models

Build a database of all my Build a database of all my assets for licensing and assets for licensing and

royalty collectionroyalty collection

Page 5: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Data ModelsData ModelsConceptualConceptual

LogicalLogical

PhysicalPhysical

Page 6: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Relational DBMSRelational DBMS

Why?Why? Performance!Performance! Reduced application development timeReduced application development time Use of SQL makes access to data more Use of SQL makes access to data more

uniform: uniform: Software modularity, Software modularity, ExtensibilityExtensibility

Page 7: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Challenge 1Challenge 1

Make students aware of the importance Make students aware of the importance of conceptual data modeling.of conceptual data modeling.

Page 8: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Challenge 1Challenge 1

Make students aware of the importance Make students aware of the importance of conceptual data modeling.of conceptual data modeling.

Solution:Solution: No-one builds a house without a design.No-one builds a house without a design.

Page 9: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Challenge 1Challenge 1

Make students aware of the importance Make students aware of the importance of conceptual data modeling.of conceptual data modeling.

Solution:Solution: No-one builds a house without a design.No-one builds a house without a design. Michael Jackson is picky and won’t pay Michael Jackson is picky and won’t pay

for a system that does not meet his for a system that does not meet his requirements.requirements.

Page 10: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Relational DBMSRelational DBMS

Why?Why? Performance!Performance! Reduced application development timeReduced application development time Use of SQL makes access to data more Use of SQL makes access to data more

uniform: uniform: Software modularity, Software modularity, ExtensibilityExtensibility

Page 11: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Challenge 2Challenge 2

Two ways to teach this course:Two ways to teach this course: How to How to implementimplement a DBMS? a DBMS?

Protocols to realize atomic property of Protocols to realize atomic property of transactionstransactions

How to How to useuse a DBMS? a DBMS? Setup a web server with a database and build Setup a web server with a database and build

a shopping baga shopping bag

Key difference: discussion at both the Key difference: discussion at both the logical and physical levelslogical and physical levels

Both require use of OO constructsBoth require use of OO constructs

Page 12: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

ChallengesChallengesConceptualConceptual

LogicalLogical

PhysicalPhysical

Abstraction, Abstraction, Inheritance, Inheritance, EncapsulationEncapsulation

Reduction to tables Reduction to tables with minimal: data with minimal: data duplication, duplication, potential for data potential for data loss and update loss and update anomaliesanomalies

Effective use of a Effective use of a DBMS, DBMS, management of management of mismatch between mismatch between tables and OO tables and OO constructsconstructs

Page 13: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Conceptual Data ModelsConceptual Data Models

Entity-Relationship (ER) data model Entity-Relationship (ER) data model Entities, Attributes, RelationshipsEntities, Attributes, Relationships

Emp

SS#

name

address

Page 14: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Conceptual Data ModelsConceptual Data Models

Entity-Relationship (ER) data model Entity-Relationship (ER) data model Entities, Attributes, RelationshipsEntities, Attributes, Relationships

Enrolledin

Emp

SS#

name

address

Health Plan

name

Co-Pay

Page 15: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Conceptual Data ModelsConceptual Data Models

Entity-Relationship (ER) data model Entity-Relationship (ER) data model Entities, Attributes, RelationshipsEntities, Attributes, Relationships Recursive relationshipsRecursive relationships

Marriedto

Emp

SS#

name

address

Page 16: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Conceptual Data ModelsConceptual Data Models

Entity-Relationship (ER) data model Entity-Relationship (ER) data model Entities, Attributes, RelationshipsEntities, Attributes, Relationships Recursive relationshipsRecursive relationships

Worksfor

Emp

SS#

name

address

Page 17: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Conceptual Data ModelsConceptual Data Models

Entity-Relationship (ER) data model Entity-Relationship (ER) data model Entities, Attributes, RelationshipsEntities, Attributes, Relationships Recursive relationshipsRecursive relationships

Worksfor

Emp

SS#

name

address

date

Page 18: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Conceptual Data ModelsConceptual Data Models

Entity-Relationship (ER) data model Entity-Relationship (ER) data model Entities, Attributes, RelationshipsEntities, Attributes, Relationships Recursive relationshipsRecursive relationships InheritanceInheritance

sidstudent

name

ISA

graduateUndergrad

SpecializationGeneralization

Page 19: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Conceptual Data ModelsConceptual Data Models

Abstraction, Inheritance, Abstraction, Inheritance, EncapsulationEncapsulation

Exercise these concepts using in-class Exercise these concepts using in-class examples and homework assignmentsexamples and homework assignments A library database contains a listing of authors who have written A library database contains a listing of authors who have written

books on various subjects (one author per book). It also contains books on various subjects (one author per book). It also contains information about libraries that carry books on various subjects.information about libraries that carry books on various subjects.

Page 20: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Conceptual Data ModelsConceptual Data Models

Abstraction, Inheritance, Abstraction, Inheritance, EncapsulationEncapsulation

Exercise these concepts using in-class Exercise these concepts using in-class examples and homework assignmentsexamples and homework assignments A library database contains a listing of authors who have written A library database contains a listing of authors who have written

books on various subjects (one author per book). It also contains books on various subjects (one author per book). It also contains information about libraries that carry books on various subjects.information about libraries that carry books on various subjects.

Entity sets: authors, subjects, books, librariesEntity sets: authors, subjects, books, libraries Relationship sets: wrote, carry, indexedRelationship sets: wrote, carry, indexed

Page 21: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Conceptual Data ModelsConceptual Data Models

Abstraction, Inheritance, Abstraction, Inheritance, EncapsulationEncapsulation

Exercise these concepts using in-class Exercise these concepts using in-class examples and homework assignmentsexamples and homework assignments A library database contains a listing of authors who have written A library database contains a listing of authors who have written

books on various subjects (one author per book). It also contains books on various subjects (one author per book). It also contains information about libraries that carry books on various subjects.information about libraries that carry books on various subjects.

carry

books indexwrote subjectauthorsSS#

name

title isbn

Subjectmatter

librariesaddress

Page 22: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Data ModelsData Models

LogicalLogical

PhysicalPhysical

WorksforEmp

SS#nameaddress

Page 23: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Relational Data ModelRelational Data Model

Prevalent in today’s market place. Prevalent in today’s market place. Why? Performance!Why? Performance!

Everything is a table!Everything is a table!

Logical data design is the process of Logical data design is the process of reducing an ER diagram to a collection reducing an ER diagram to a collection of tables.of tables.

Page 24: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Logical Data DesignLogical Data Design

Trivial reduction:Trivial reduction: An entity set = a tableAn entity set = a table A relationship set = a tableA relationship set = a table

Pitfalls: Pitfalls: Duplication of data Duplication of data Unintentional loss of dataUnintentional loss of data Data ambiguity that impacts software Data ambiguity that impacts software

design, resulting in update anomaliesdesign, resulting in update anomalies

Page 25: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Data DuplicationData Duplication

Worksfor

Emp

SS#

name

address

396396 ShahramShahram SeattleSeattle

400400 AsokeAsoke ChicagoChicago

200200 JoeJoe New YorkNew York

396396 400400

200200 400400

120120 400400

SS#SS# NameName AddressAddress SS#SS# MGRMGR

SS#SS#

Page 26: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Data DuplicationData Duplication

The SS# column is duplicated!The SS# column is duplicated!

Worksfor

Emp

SS#

name

address

396396 ShahramShahram SeattleSeattle

400400 AsokeAsoke ChicagoChicago

200200 JoeJoe New YorkNew York

396396 400400

200200 400400

120120 400400

SS#SS# NameName AddressAddress SS#SS# MGRMGR

SS#SS#

Page 27: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Data Duplication: SolutionData Duplication: Solution Merge the two tables into one:Merge the two tables into one:

396396 ShahramShahram SeattleSeattle 400400

400400 AsokeAsoke ChicagoChicago NULLNULL

200200 JoeJoe New YorkNew York 400400

SS#SS# NameName AddressAddress MGRMGR

SS#SS#

Worksfor

Emp

SS#

name

address

Page 28: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Data LossData Loss

Ford maintains warehouses containing Ford maintains warehouses containing different automobile partsdifferent automobile parts

Records are inserted and deleted Records are inserted and deleted based on availability of a part at a based on availability of a part at a warehousewarehouse

123123 PistonPiston TijuanaTijuana

203203 CylinderCylinder MichiganMichigan

877877 BumperBumper MichiganMichigan

389389 SeatsSeats ArizonaArizona

Part#Part# DescriptionDescription LocationLocation

Page 29: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Data Loss (Cont…)Data Loss (Cont…)

When a warehouse becomes empty, it When a warehouse becomes empty, it is lost from the database:is lost from the database:

Solution: utilize two different tablesSolution: utilize two different tables

123123 PistonPiston TijuanaTijuana

389389 SeatsSeats ArizonaArizona

Part#Part# DescriptionDescription LocationLocation

123123 PistonPiston 1212

389389 SeatsSeats 4545

Part#Part# DescriptionDescription WHIDWHID

1212 TijuanaTijuana

4545 ArizonaArizona

WHIDWHID LocationLocation

Page 30: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Data AmbiguityData Ambiguity

Represent faculty of a department as:Represent faculty of a department as:

A change of address for a faculty might A change of address for a faculty might be for the entire department. This be for the entire department. This cannot be differentiated with this table cannot be differentiated with this table design!design!

GhandeharizadehGhandeharizadeh Comp SciComp Sci SALSAL

PapadopoulosPapadopoulos Comp SciComp Sci SALSAL

BohemBohem Comp SciComp Sci SALSAL

FacultyFaculty DepartmentDepartment LocationLocation

Page 31: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Data AmbiguityData Ambiguity

Utilize two tables:Utilize two tables:

GhandeharizadehGhandeharizadeh Comp SciComp Sci

PapadopoulosPapadopoulos Comp SciComp Sci

JenkinsJenkins Bio MedicalBio Medical

BohemBohem Comp SciComp Sci

FacultyFaculty DepartmentDepartment

Comp SciComp Sci SALSAL

Sex EdSex Ed BOVARDBOVARD

Bio MedicalBio Medical HEDCOHEDCO

DepartmentDepartment LocationLocation

Page 32: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Data Ambiguity (Cont…)Data Ambiguity (Cont…)

Employees of a bi-lingual company Employees of a bi-lingual company having different skills.having different skills.

Update anomalies!Update anomalies!

AsokeAsoke TeachTeach HindiHindi

AsokeAsoke CookCook FrenchFrench

AsokeAsoke NullNull GermanGerman

AsokeAsoke ProgramProgram EnglishEnglish

EmployeeEmployee SkillSkill LanguageLanguage

Page 33: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Data Ambiguity: SolutionData Ambiguity: Solution

Utilize two tables:Utilize two tables:

AsokeAsoke TeachTeach

AsokeAsoke CookCook

AsokeAsoke ProgramProgram

EmployeeEmployee SkillSkillAsokeAsoke HindiHindi

AsokeAsoke FrenchFrench

AsokeAsoke GermanGerman

AsokeAsoke EnglishEnglish

EmployeeEmployee LanguageLanguage

Page 34: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Logical Data DesignLogical Data Design

A quest to flatten objects with minimal A quest to flatten objects with minimal data duplication, loss of data, and data duplication, loss of data, and update anomalies!update anomalies!

William Kent, “A Simple Guide to Five William Kent, “A Simple Guide to Five Normal Forms in Relational Database Normal Forms in Relational Database Theory”, Communications of the ACM Theory”, Communications of the ACM 26(2), Feb 1983, 120-125.26(2), Feb 1983, 120-125.

Page 35: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Data ModelsData Models

PhysicalPhysical

WorksforEmp

SS#nameaddress

Logical Data DesignLogical Data Design

396396 ShahramShahram SeattleSeattle 400400

400400 AsokeAsoke ChicagoChicago NullNull

SS#SS# NameName AddressAddress MGR SS#MGR SS#

Page 36: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Physical ImplementationPhysical Implementation

Reconstruct main memory objects for Reconstruct main memory objects for manipulation and presentation:manipulation and presentation: Specify class definitionsSpecify class definitions

Typically correspond to entity-setsTypically correspond to entity-sets

Populate an instance of a class by issuing Populate an instance of a class by issuing SQL queries to a DBMSSQL queries to a DBMS

Update instances in memoryUpdate instances in memory Flush dirty instances back to DBMSFlush dirty instances back to DBMS

Potential use of transactionsPotential use of transactions

Page 37: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Type MismatchType Mismatch

A column of a row must be a primitive A column of a row must be a primitive such as an integer, real, etc.such as an integer, real, etc. It may NOT be an array of integers or It may NOT be an array of integers or

object pointersobject pointers

A property (attribute) of a class might A property (attribute) of a class might be of a multi-valued type, e.g., an array, be of a multi-valued type, e.g., an array, a vector, etc.a vector, etc.

Changes in software may impact the Changes in software may impact the design of tables. (Management of type design of tables. (Management of type mismatch by the system designer.)mismatch by the system designer.)

Page 38: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

ImplementationImplementation

Set operators in the DBMSSet operators in the DBMS Does set A contain set B?Does set A contain set B? Does value v1 appear in set A?Does value v1 appear in set A?

Aggregates in the DBMSAggregates in the DBMS Compute average employee salaryCompute average employee salary Count the number of employeesCount the number of employees Find the oldest employeeFind the oldest employee

Page 39: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

ChallengesChallengesConceptualConceptual

LogicalLogical

PhysicalPhysical

Abstraction, Abstraction, Inheritance, Inheritance, EncapsulationEncapsulation

Reduction to tables Reduction to tables with minimal: data with minimal: data duplication, duplication, potential for data potential for data loss and update loss and update anomaliesanomalies

Effective use of a Effective use of a DBMS, DBMS, management of management of mismatch between mismatch between tables and OO tables and OO constructsconstructs

Page 40: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

A Shift in ComputingA Shift in Computing

1985-20001985-2000 1999+1999+Server-centricServer-centric DistributedDistributedDumb clientsDumb clients Smart clientsSmart clientsHardware-drivenHardware-driven Software-drivenSoftware-drivenUser to appUser to app User to app; app to appUser to app; app to appInformation accessInformation access Information actionInformation actionOne-wayOne-way Two-wayTwo-wayMonolithic islandsMonolithic islands peer-to-peerpeer-to-peerIntegration an afterthoughtIntegration an afterthought Integration by designIntegration by designChallenge: scaleChallenge: scale Challenge: valueChallenge: value

InternetInternet

Page 41: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Future VisionFuture Vision In the future, any two IT components will In the future, any two IT components will

automatically integrate and “communicate” with automatically integrate and “communicate” with one another, one another, eveneven though they were not though they were not specifically designed to interoperatespecifically designed to interoperate

How?How? SemanticsSemantics StandardsStandards Concept of “software and data” as a service, web Concept of “software and data” as a service, web

service, e.g.,service, e.g., Google as a web serviceGoogle as a web service Microsoft Teraserver web servicesMicrosoft Teraserver web services Experian (TRW) credit report web servicesExperian (TRW) credit report web services Etc.Etc.

Page 42: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

XMLXML A standard for data interoperability among web A standard for data interoperability among web

servicesservices Language independentLanguage independent

Sun’s Java, Microsoft’s C#Sun’s Java, Microsoft’s C#

Device and software platform independentDevice and software platform independent

Motorola i85sMotorola i85s J2MEJ2ME

Compaq iPAQCompaq iPAQ Windows CEWindows CE StrongARMStrongARM

PERLPERL Apache 2.0Apache 2.0 MySQLMySQL LinuxLinux

.NET.NET SQL 2000SQL 2000 Commerce serverCommerce server Windows 2000Windows 2000

Page 43: Challenges of Teaching OO Constructs with Databases Shahram Ghandeharizadeh Database Laboratory Computer Science Department University of Southern California.

Future ChallengeFuture Challenge

Educate students to see Internet as an Educate students to see Internet as an object-oriented software platform!object-oriented software platform!

Software at an Internet scale must be:Software at an Internet scale must be: Robust: Physical location independenceRobust: Physical location independence Ensure availability of data and Ensure availability of data and

functionality at all timesfunctionality at all times Modular and ExtendibleModular and Extendible Integrate with other software componentsIntegrate with other software components