V 1.0 DBMAN 9 Inheritance Modeling + Relational Databases 1.

Slides:



Advertisements
Similar presentations
Chapter 10: Designing Databases
Advertisements

Michael Pizzo Software Architect Data Programmability Microsoft Corporation.
Introduction to Databases
.NET Database Technologies: Open-Source Frameworks.
Chapter 1 Object-Oriented System Development
Object-Oriented Databases v OO systems associated with – graphical user interface (GUI) – powerful modeling techniques – advanced data management capabilities.
1 SWE Introduction to Software Engineering Lecture 23 – Architectural Design (Chapter 13)
File Systems and Databases
Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar.
Geographic Information Systems
Object-Oriented Databases
Chapter 11 Data Management Layer Design
ASP.NET Programming with C# and SQL Server First Edition
ORM Object-Relational Mapping 1. Object Persistence Persistence is the ability of an object to survive the lifecycle of the process, in which it resides.
RIZWAN REHMAN, CCS, DU. Advantages of ORDBMSs  The main advantages of extending the relational data model come from reuse and sharing.  Reuse comes.
Data Access Patterns. Motivation Most software systems require persistent data (i.e. data that persists between program executions). In general, distributing.
IST Databases and DBMSs Todd S. Bacastow January 2005.
Architecture of Enterprise Systems: Domain Model and Database layer
Chapter 2 Architectural Models. Keywords Middleware Interface vs. implementation Client-server models OOP.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented Design.
Week 1 Lecture MSCD 600 Database Architecture Samuel ConnSamuel Conn, Asst. Professor Suggestions for using the Lecture Slides.
Entity Framework Code First End to End
DBMS Lecture 9  Object Database Management Group –12 Rules for an OODBMS –Components of the ODMG standard  OODBMS Object Model Schema  OO Data Model.
CISC6795: Spring Object-Oriented Programming: Polymorphism.
Data Access Patterns Some of the problems with data access from OO programs: 1.Data source and OO program use different data modelling concepts 2.Decoupling.
NHibernate in Action Web Seminar at UMLChina By Pierre Henri Kuaté 2008/08/27
Copyright 2002 Prentice-Hall, Inc. Modern Systems Analysis and Design Third Edition Jeffrey A. Hoffer Joey F. George Joseph S. Valacich Chapter 20 Object-Oriented.
.NET Database Technologies: Data Models and Patterns.
CSC 211 Introduction to Design Patterns. Intro to the course Syllabus About the textbook – Read the introduction and Chapter 1 Good attendance is the.
Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.
Chapter 9 Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design.
Object Oriented Analysis and Design 1 Chapter 7 Database Design  UML Specification for Data Modeling  The Relational Data Model and Object Model  Persistence.
Object Persistence Design Chapter 13. Key Definitions Object persistence involves the selection of a storage format and optimization for performance.
Architectural Design Yonsei University 2 nd Semester, 2014 Sanghyun Park.
Chapter 12: Designing Databases
DAAD project “Joint Course on OOP using Java” On Object Oriented modeling in Java (Why & How) Ana Madevska Bogdanova Institute of informatics Faculty of.
© 2005 Prentice Hall10-1 Stumpf and Teague Object-Oriented Systems Analysis and Design with UML.
1 Mapping to Relational Databases Presented by Ramona Su.
Domain and Persistence Patterns. Fundamental Pattern Types Design Patterns Business Logic Patterns.
Unified Modeling Language © 2002 by Dietrich and Urban1 ADVANCED DATABASE CONCEPTS Unified Modeling Language Susan D. Urban and Suzanne W. Dietrich Department.
Design Patterns Gang Qian Department of Computer Science University of Central Oklahoma.
Object Oriented Software Development
CSCI-383 Object-Oriented Programming & Design Lecture 10.
Object-Oriented Programming Chapter Chapter
Object Oriented Programming
Testing OO software. State Based Testing State machine: implementation-independent specification (model) of the dynamic behaviour of the system State:
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 6: Using Design Patterns.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
Coming up: Inheritance
Mapping Objects ↔Relational DB. The Problem with Databases Databases store data in rows in tables, which are not like objects. We can simulate object.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
Object- oriented Design Principles
1 10 Systems Analysis and Design in a Changing World, 2 nd Edition, Satzinger, Jackson, & Burd Chapter 10 Designing Databases.
ORM Basics Repository Pattern, Models, Entity Manager Ivan Yonkov Technical Trainer Software University
OODBMS and ORDBMS. Background Object-oriented software, based on the principles of user-defined datatypes, along with inheritance and polymorphism, is.
Data Models. 2 The Importance of Data Models Data models –Relatively simple representations, usually graphical, of complex real-world data structures.
DBS201: Data Modeling. Agenda Data Modeling Types of Models Entity Relationship Model.
Relational vs. Object Oriented Database Management System Syazwani Nur Dayana Nur Fatin Syafiqa M3cs2305B.
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)
Entity Framework By: Casey Griffin.
DBMAN 8 Inheritance Modeling in Relational Databases
Inheritance B.Ramamurthy 11/7/2018 B.Ramamurthy.
DBMAN 8 Database Access Layers The ORM Pattern
File Systems and Databases
Data Model.
Chapter 19: Interfaces and Components
Developing and testing enterprise Java applications
Presentation transcript:

V 1.0 DBMAN 9 Inheritance Modeling + Relational Databases 1

V 1.0 Inheritance vs relations OOP = Objects  Inheritance Relational database = Tables  Relationships Main question: how to map the OO class hierarchy to a table hierarchy? in an ER, we usually see HAS-A / PART-OF / IS-A / INSTANCE-OF relationships 2

V 1.0 HAS-A / PART-OF In OOP: association, aggregation, composition Association: “accidental” connection Aggregation: “strong association”, separate lifetimes Composition: “strong aggregation”, connected lifetimes In RDBMS: Holonymy (HAS-A) / Meronymy (PART-OF) –'tree' is a holonym of 'bark', of 'trunk' and of 'limb.‘ –"finger" is a meronym of "hand" because a finger is part of a hand. Similarly, "wheels" is a meronym of "automobile" 3

V 1.0 HAS-A / PART-OF These relationships are usually described using simple FK connections 1:N or M:N  depends on the actual objects In the OOP world, a List data field is N:M, a simple “Something” data field is a 1:N relationship HAS-A or PART-OF: depends on the source/destination of the relationship arrow 4

V 1.0 IS-A / INSTANCE-OF a token (object) has an instance-of relationship with its type (class) (in OOP: instantiation, in DB: usually 1:N FK) a hyponym (subtype, subclass) has a type-of (is-a) relationship with its hypernym (supertype, superclass); (in OOP: inheritance) IS-A in DB??? Not easy... 5

V 1.0 OOP mapping ORM = Object-relational mapping Mapping (v). The act of determining how objects and their relationships are persisted in permanent data storage, in this case relational databases. Mapping (n). The definition of how an object’s property or a relationship is persisted in permanent storage. mapping-to-rdb/#h5 6

V Single Table Inheritance 7

V Single Table Inheritance - Advantages Simple approach. Easy to add new classes, you just need to add new columns for the additional data. Supports polymorphism by simply changing the type of the row. Data access is fast because the data is in one table. Ad-hoc reporting is very easy because all of the data is found in one table. 8

V Single Table Inheritance - Disadvantages Coupling within the class hierarchy is increased because all classes are directly coupled to the same table. A change in one class can affect the table which can then affect the other classes in the hierarchy. Space potentially wasted in the database. Indicating the type becomes complex when significant overlap between types exists. Table can grow quickly for large hierarchies.  ideal for simple and/or shallow class hierarchies where there is little or no overlap between the types within the hierarchy. 9

V Concrete Table Inheritance 10

V Concrete Table Inheritance - Advantages Easy to do ad-hoc reporting as all the data you need about a single class is stored in only one table. Good performance to access a single object’s data. 11

V Concrete Table Inheritance - Disadvantages When you modify a class you need to modify its table and the table of any of its subclasses. Whenever an object changes its role, you need to copy the data into the appropriate table and assign it a new ID value (or perhaps you could reuse the existing ID value). It is difficult to support multiple roles and still maintain data integrity. For example, where would you store the name of someone who plays two sports?  When changing types and/or overlap between types is rare. 12

V Class Table Inheritance 13

V Class Table Inheritance – Advantages Easy to understand because of the one-to-one mapping. Supports polymorphism very well as you merely have records in the appropriate tables for each type. Very easy to modify superclasses and add new subclasses as you merely need to modify/add one table. Data size grows in direct proportion to growth in the number of objects. 14

V Class Table Inheritance – Disadvantages There are many tables in the database, one for every class (plus tables to maintain relationships). Potentially takes longer to read and write data using this technique because you need to access multiple tables. (can be improved using striped RAID!) Ad-hoc reporting on your database is difficult, unless you add views to simulate the desired tables.  When there is significant overlap between types or when changing types is common. 15

V 1.0 Comparison 16 Factors to ConsiderOne table per hierarchy One table per concrete class One table per class Ad hoc reportingSimpleMediumMedium / Difficult Ease of implementation SimpleMediumDifficult Ease of data accessSimple Medium / Simple CouplingVery highHighLow Speed of data access Fast Medium / Fast Support for polymorphism MediumLowHigh

V Generic Table Structure 17

V Generic Table Structure – Advantages Only structure to support multiple inheritance (e.g. C++) Works very well when database access is encapsulated by a robust persistence framework. It can be extended to provide meta data to support a wide range of mappings, including relationship mappings. In short, it is the start at a mapping meta data engine. It is incredibly flexible, enabling you to quickly change the way that you store objects because you merely need to update the meta data stored in the Class, Inheritance, Attribute, and AttributeType tables accordingly. 18

V 1.0. Generic Table Structure – Disadvantages Very advanced technique that can be difficult to implement at first. It only works for small amounts of data because you need to access many database rows to build a single object. You will likely want to build a small administration application to maintain the meta data. Reporting against this data can be very difficult due to the need to access several rows to obtain the data for a single object.  For complex applications that work with small amounts of data, or where you data access isn’t very common or you can pre-load data into caches. 19

V 1.0 ORM + REPOSITORY 20

V 1.0 Design pattern? “Design Patterns provide standardized and efficient solutions to software design and programming problems that are re-usable in your code. Software Architects and developers use them to build high quality robust applications. However, you have to take care to select the right pattern for the right problem.” (unfinished) (full, but 21

V 1.0 ORM = Anti-Pattern? “ORM is a terrible anti-pattern that violates all principles of object-oriented programming, tearing objects apart and turning them into dumb and passive data bags. There is no excuse for ORM existence in any application” Okay, I do not agree with this article – nor does most of the developers: Hibernate for Java, ActiveRecord for Ruby on Rails, Doctrine for PHP, and SQLAlchemy for Python... And Entity Framework for C# But it must be noted, that ORM frameworks tend to be slow / weak in funcionality / bad in memory management 22

V 1.0 ORM in.NET = Entity Framework 23

V 1.0 ORM Syntax In addition to plain old SQL processing, an ORM adds support to: –Types, as entities are fully typed. –EntitySets, which are treated as collections of entities. –Composability, which removes restrictions on where subqueries can be used. New query syntax: LINQ All of that will be detailed in next semester. Let’s assume we have a working DAL. How can we separate the DAL and the BL layers? 24

V 1.0 Repository pattern? A Repository mediates between the domain and data mapping layers Acting like an in-memory domain object collection. Mediator? “An object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently. “ 25

V 1.0 Repository layers 26

V 1.0 Operation of a repository Client objects construct query specifications declaratively and submit them to Repository for satisfaction. Objects can be added to and removed from the Repository, as they can from a simple collection of objects, and the mapping code encapsulated by the Repository will carry out the appropriate operations A Repository encapsulates the set of objects persisted in a data store and the operations performed over them, providing a more object-oriented view of the persistence layer Unfortunately we need lambda expressions to develop it in C#... So we cannot do it... 27

V 1.0 Repository pattern - Interfaces 28

V 1.0 Repository pattern - Classes 29

V

31