INHERITANCE.

Slides:



Advertisements
Similar presentations
Has-a Relationships A pen “has a” or “contains a” ball.
Advertisements

Object Oriented Programming
Behavioral Pattern: Template Method C h a p t e r 5 – P a g e 217 On occasion, two different components in a software system will have significant similarities,
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
Iterators T.J. Niglio Computer & Systems Engineering Fall 2003 Software Design & Documentation Object Behavioral.
Movies length titleyearfilmType Voices isa Cartoons isa MurderMystery weapon toStar Our Movie Example.
Chapter 11 Data Management Layer Design
IEG3080 Tutorial 11 Prepared by Ryan. Outline Enterprise Application Architecture Layering Structure Domain Logic C# Attribute Aspect Oriented Programming.
Architecture of Enterprise Systems: Domain Model and Database layer
Inheritance using Java
Programming Languages and Paradigms Object-Oriented Programming.
1 Intro to Info Tech Database Management Systems Copyright 2003 by Janson Industries This presentation can be viewed on line at:
What is Architecture  Architecture is a subjective thing, a shared understanding of a system’s design by the expert developers on a project  In the.
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.
Game Programming Patterns Type Object From the book by Robert Nystrom
Hibernate Persistence. What is Persistence Persist data to database or other storage.  In OO world, persistence means persist object to external storage.
Spring 2009Computer Science Department, TUC-N Object Oriented Methods Architectural Patterns 3.
Architectural Patterns Support Lecture. Software Architecture l Architecture is OVERLOADED System architecture Application architecture l Architecture.
1 Mapping to Relational Databases Presented by Ramona Su.
Pertemuan 10 Enterprise Application Patterns Mata kuliah: T0144 – Advanced Topics in Software Engineering Tahun: 2010.
Refactoring Deciding what to make a superclass or interface is difficult. Some of these refactorings are helpful. Some research items include Inheritance.
Design Patterns Gang Qian Department of Computer Science University of Central Oklahoma.
Chapter 38 Persistence Framework with Patterns 1CS6359 Fall 2011 John Cole.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Define an interface for creating an object, but let subclasses decide which class to instantiate.
Object Oriented Database By Ashish Kaul References from Professor Lee’s presentations and the Web.
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
C++ Inheritance Data Structures & OO Development I 1 Computer Science Dept Va Tech June 2007 © McQuain Generalization versus Abstraction Abstraction:simplify.
Elaboration Iteration 3 – Part 3 - Persistence Framework -
Interfaces F What is an Interface? F Creating an Interface F Implementing an Interface F What is Marker Interface?
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming.
Neo.NET Entity Objects Architecture and Implementation Copyright © Erik Dörnenburg – Last updated: December 2004.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
MAITRAYEE MUKERJI Object Oriented Programming in C++: Hierarchy / Inheritance.
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
OpenAccess ORM Advanced Topics Kevin Babcock April 9, 2009.
Lecture 8 D&D Chapter 9 Inheritance Date.
Architecture Patterns Design Patterns
Web Design & Development Lecture 9
Sections Inheritance and Abstract Classes
Programming Languages Dan Grossman 2013
Chapter 5 Database Design
Architecture Patterns and Refactoring
INLS 623– Database Systems II– File Structures, Indexing, and Hashing
Object-Oriented Programming (OOP) Lecture No. 45
Low Budget Productions, LLC
Informatica PowerCenter Performance Tuning Tips
Creational Pattern: Prototype
Object-Oriented Programming
CPSC-310 Database Systems
Hibernate (JPA) Code First Entity Relations
SQL: Advanced Options, Updates and Views Lecturer: Dr Pavle Mogin
Datamining : Refers to extracting or mining knowledge from large amounts of data Applications : Market Analysis Fraud Detection Customer Retention Production.
COS 346 Day 8.
CSC 205 Java Programming II
Object Oriented Analysis and Design
Domain Class Diagram Chapter 4 Part 2 pp
Lecture 22 Inheritance Richard Gesick.
Object oriented vs procedural programming
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
OO Design with Inheritance
Why inheritance? shape mammal map
Advanced Database Concepts: Reports & Views
Adapter Design Pattern
Microsoft Access Validation Rules, Table Relationships And
Indexes and more Table Creation
Database management systems
Presentation transcript:

INHERITANCE

What this presentation ...won’t be about Inheritance as one of the pillars of OOP Implementation of inheritance

What this presentation ...will be about Inheritance as a part of “Enterprise application” Inheritance in relation with relational database Martin Fowler: Patterns of Enterprise Application Architecture (2002/2003)

Enterprise applications “Enterprise software, also known as enterprise application software (EAS), is computer software used to satisfy the needs of an organization rather than individual users.!”        Wikipedia Persistent data A lot of data Concurrent data access Complex business (il)logic Integration with other enterprise systems

Player name Cricketer batting average Footballer club Bowler bowling average

Object Mapper create load save Table

Relational databases don’t support inheritance Object Mapper create load save Table Relational databases don’t support inheritance

Object-Relational structural patterns Single table inheritance Class table inheritance Concrete table inheritance Inheritance mappers

Single table inheritance Player name Footballer club Cricketer batting average Bowler bowling average <<table>> Players name club baiting average bowling average type

Single table inheritance Strengths of STI: Single table in database No joins in retrieving data Moving fields up/down the hierarchy does not require database changes Weaknesses of STI: Fields might not be relevant for everybody Fields used only by some subclasses lead to wasted space Single tables may end up being too large – may hurt performance Single namespace for fields

Concrete table inheritance Footballers name club Player name Footballer club Cricketer batting average Bowler bowling average <<table>> Cricketers name baiting average <<table>> Bowlers name baiting average bowling average

Concrete table inheritance Strengths of CTI: No irrelevant fields No joins when reading the data from concrete mappers Each table is accessed only when concrete class is accessed Weakness of CTI: Primary keys can be difficult to handle Moving fields up/down the hierarchy does require database changes Superclass fields are duplicated across the tables – changes in superclass mean changes in each table A find on superclass forces you to check all the tables

Class table inheritance Player name Footballer club Cricketer batting average Bowler bowling average <<table>> Footballers club Cricketers baiting average Bowlers bowling average Players name

Class table inheritance Strengths of CTI: All columns are relevant for every row – no wasted space The relationship database x domain model is straightforward Weaknesses of CTI: Need of accessing multiple tables in order to load object – joins or multiple queries Moving fields up/down the hierarchy does require database changes The supertype tables may become bottleneck because they have to be accessed frequently

Single table vs. Class table vs. Concrete table Trade-off between performance, duplicate data, readability,… Trio of patterns can coexist in a single hierarchy: Concrete table inheritance + Single table inheritance Class table inheritance + Concrete table inheritance Possibly more…

Abstract player mapper Generic inheritance mapper Mapper + insert + update + delete # save # load Abstract player mapper # save # load Footballer mapper + find(key) : Footballer # save # load Cricketer mapper + find(key) : Cricketer # save # load Player mapper + find(key) : Player # insert # update Bowler mapper + find(key) : Bowler # save # load

// The gateway's data property is a data set that can be loaded by a query. class Mapper { ... protected DataTable table { get {return Gateway.Data.Tables[TableName];} } protected Gateway Gateway; abstract protected String TableName {get;} // Since there is only one table, this can be defined by the abstract player mapper. class AbstractPlayerMapper : Mapper { protected override String TableName { get {return "Players";}

// Each class needs a type code to help the mapper code figure out what kind of player it's dealing with. The type code is defined on the superclass and implemented in the subclasses. class AbstractPlayerMapper : Mapper { ... abstract public String TypeCode {get;} } class CricketerMapper : AbstractPlayerMapper { public const String TYPE_CODE = "C"; public override String TypeCode { get {return TYPE_CODE;}

// The player mapper has fields for each of the three concrete mapper classes. class PlayerMapper : Mapper { ... private BowlerMapper bmapper; private CricketerMapper cmapper; private FootballerMapper fmapper; public PlayerMapper (Gateway gateway) : base (gateway) { bmapper = new BowlerMapper(Gateway); cmapper = new CricketerMapper(Gateway); fmapper = new FootballerMapper(Gateway); }

// Loading an Object from the Database // Each concrete mapper class has a find method to get an object from the data. class CricketerMapper : AbstractPlayerMapper { ... public Cricketer Find(long id) { return (Cricketer) AbstractFind(id); }

// This calls generic behavior to find an object. class Mapper { ... protected DomainObject AbstractFind(long id) { DataRow row = FindRow(id); return (row == null) ? null : Find(row); } protected DataRow FindRow(long id) { String filter = String.Format("id = {0}", id); DataRow[] results = table.Select(filter); return (results.Length == 0) ? null : results[0]; public DomainObject Find (DataRow row) { DomainObject result = CreateDomainObject(); Load(result, row); return result; abstract protected DomainObject CreateDomainObject();

// I load the data into the new object with a series of load methods, one on each class in the hierarchy. class CricketerMapper : AbstractPlayerMapper { ... protected override void Load(DomainObject obj, DataRow row) { base.Load(obj,row); Cricketer cricketer = (Cricketer) obj; cricketer.battingAverage = (double)row["battingAverage"]; } } class AbstractPlayerMapper : Mapper { base.Load(obj, row); Player player = (Player) obj; player.name = (String)row["name"]; class Mapper { protected virtual void Load(DomainObject obj, DataRow row) { obj.Id = (int) row ["id"];

// I can also load a player through the player mapper // I can also load a player through the player mapper. It needs to read the data and use the type code to determine which concrete mapper to use. class PlayerMapper : Mapper { ... public Player Find (long key) { DataRow row = FindRow(key); if (row == null) return null; else { String typecode = (String) row["type"]; switch (typecode){ case BowlerMapper.TYPE_CODE: return (Player) bmapper.Find(row); case CricketerMapper.TYPE_CODE: return (Player) cmapper.Find(row); case FootballerMapper.TYPE_CODE: return (Player) fmapper.Find(row); default: throw new Exception("unknown type"); }