Inheritance & Classification Hierarchies Lecture-8.

Slides:



Advertisements
Similar presentations
OBJECT-ORIENTEDNESS. What is Object-Orientedness? model system as a collection of interacting objects O-O Modelling  O-O Programming ► similar conceptual.
Advertisements

4. Object-Oriented Programming Procedural programming Structs and objects Object-oriented programming Concepts and terminology Related keywords.
AB C D Clickers x. AB C D x  Today we’re going to be working with some special right triangles that occur within other geometric figures  The ratios.
1 l Inheritance Basics l Programming with Inheritance l Dynamic Binding and Polymorphism Inheritance.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 8 Slide 1 System modeling 2.
CS 211 Inheritance AAA.
Chapter 8 Inheritance Part 2. © 2004 Pearson Addison-Wesley. All rights reserved8-2 Outline Creating Subclasses Overriding Methods Class Hierarchies Inheritance.
Inheritance Java permits you to use your user defined classes to create programs using inheritance.
Object-Oriented Programming (OOP) Lecture No. 6
L3-1-S1 OO Concepts © M.E. Fayad SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
PowerPoint Presentation for Dennis & Haley Wixom, Systems Analysis and Design Copyright 2000 © John Wiley & Sons, Inc. All rights reserved. Slide 1 The.
Slides prepared by Rose Williams, Binghamton University Chapter 7 Inheritance.
OBJECT-ORIENTED DBMS. Structured & Object Oriented Approaches Structured approach – long history, well- documented  ERD - modeling data  DFD - modeling.
1 Software Testing and Quality Assurance Lecture 28 – Testing Class Hierarchies.
1 Inheritance and Polymorphism Inheritance (Continued) Polymorphism Polymorphism by inheritance Polymorphism by interfaces Reading for this lecture: L&L.
BACS 287 Basics of Object-Oriented Programming 1.
CPT 140 Programming Constructs1 OBJECT ORIENTED TECHNOLOGY Terminology and Basic Concepts.
2.5 OOP Principles Part 2 academy.zariba.com 1. Lecture Content 1.Polymorphism 2.Cohesion 3.Coupling 2.
Inheritance One of the biggest advantages of object-oriented design is that of inheritance. A class may be derived from another class, the base class.
DBMS Lecture 9  Object Database Management Group –12 Rules for an OODBMS –Components of the ODMG standard  OODBMS Object Model Schema  OO Data Model.
1 What is Inheritance? zThe mechanism of deriving a new class from an old one is called inheritance zClasses organised into a ‘classification hierarchy’
The Pythagorean Theorem
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.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 2 1 Java Inheritance.
Types of 2 D Shapes and There Properties 1)A shape with 3 sides is called a triangle 2)A shape with 4 sides is called a quadrilateral 3)The general term.
CS3773 Software Engineering Lecture 04 UML Class Diagram.
Software Engineering, 8th edition Chapter 8 1 Courtesy: ©Ian Somerville 2006 April 06 th, 2009 Lecture # 13 System models.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Inheritance Notes Chapter 6 1. Inheritance  you know a lot about an object by knowing its class  for example what is a Komondor? 2
CSCI-383 Object-Oriented Programming & Design Lecture 10.
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
Special Right Triangles
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Chapter 8 Specialization aka Inheritance. 2 Inheritance  Review of class relationships  Uses – One class uses the services of another class, either.
Chapter 8 Inheritance. 2  Review of class relationships  Uses – One class uses the services of another class, either by making objects of that class.
Triangles 1st year P26 Chapter 4.
Chapter 12 Object-oriented design for more than one class.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 12 Inheritance and Class Design 1.
CET203 SOFTWARE DEVELOPMENT Session 2A Inheritance (programming in C#)
Java Software Solutions Lewis and Loftus Chapter 8 Copyright 1997 by John Lewis and William Loftus. All rights reserved. 1 Inheritance -- Introduction.
Object Modeling THETOPPERSWAY.COM. Object Modelling Technique(OMT)  Building a model of an application domain and then adding implementation.
Inheritance in C++ Bryce Boe 2012/08/28 CS32, Summer 2012 B.
1 SWE Introduction to Software Engineering Lecture 14 – System Modeling.
CSC241 Object-Oriented Programming (OOP) Lecture No. 2.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Inheritance & Classification Hierarchies Lecture-8.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Object Oriented Programming
The Movement To Objects
OBJECT ORIENTED CONCEPT
Object-Oriented Analysis and Design
Object-Oriented Programming
Properties of Triangles
An Introduction to Inheritance
Properties of Triangles
Inheritance "Question: What is the object oriented way of getting rich? Answer: Inheritance.“ “Inheritance is new code that reuses old code. Polymorphism.
Rectangle Rest Find angle

Identify type of triangle
Object Oriented Analysis and Design
The Super 9 – Angles GOOD – calculate the missing angles
Chapter 7 Inheritance.
Programming in C# CHAPTER 5 & 6
Cs212: Data Structures Lecture 7: Tree_Part1
Presentation transcript:

Inheritance & Classification Hierarchies Lecture-8

Inheritance & Classification Hierarchies Inheritance is one of the most powerful features of O-O programming By organising classes into Classification Hierarchies we can add extra dimensions to encapsulation by grouping ADT's and enables classes to inherit from other classes thus extending the attributes and methods of the class which inherits The inheriting class may then also add extra functionality and attributes to produce a new object

Terminology of inheritance The following terms are used to describe the different inheritance properties of an object Derived Class or Sub Class or Child Class  A Class which inherits some of its attributes and methods from another class Base Class or superclass or Parent Class  A Class from which another class inherits Ancestor  A Classes ancestors are those from which its own superclass inherit Descendant  A classes descendants are those which inherit from its superclasses

Why do we need Inheritance ? What is the purpose of inheritance and why should we wish to inherit the attributes and methods of other Objects ? There are two main reasons for using inheritance in O-O which are  Specialisation Extending the functionality of an existing class  Generalisation Sharing commonality between two or more classes

Classification Hierarchy The product of inheritance is a classification Hierarchy This is a relationship between classes where one class is said to be 'a kind of' other class As the class hierarchy is traversed from top to bottom we move from generalisation to specialisation of classes This is done by adding functionality to extend what exists at each level of the class hierarchy from the base class

An Example Geometric Object 2D3D TriangleSquareSphereCube

Class Hierarchy Diagram The base of this diagram is the Geometric Object class From this the 2D and 3D objects inherit the base features ( what could these be ?) After this there are specialised versions of the classes using the 'kind of' relationship where 2D objects such as triangle and Square inherit the base classes of a Geometric Object and then add special features specific to the type of object The same then applies for the other classes This tree runs from a generalisation of the base class to a specialisation of the actual object

'a kind of' or 'a part of' Each level of a classification hierarchy contains more specific types of class each one of which must be 'a kind of' the class from which it inherits This distinction is important as the difference between 'a kind of' and 'a part of' is very different The distinction between different Objects and the same Objects with different states This mean analysis to see if difference of Objects are dependent upon the Object type or a state of that Object  For Example Equilateral Triangle and Isosceles Triangle are inappropriate Object classifications as they are both really triangles (with just the angle between vertices being different) which we could store in a general triangle class

What Do Objects Inherit ? A class does not contain any state values, only a 'blue print' for what value are to be contained Therefore a 'derived class' inherits all of the attributes from the 'base class' A derived class is by definition identical to the base class, but it can be built on to extend and modify the base class Objects of the derived class do not inherit anything from the objects of the base class As far as objects are concerned there is no hierarchy

Example Line +startPosition: +endPosition: +Draw() Line Object start = (x,y) end = (x,y) draw(star,end) ColoredLine +color +set color() Line Object start = (x,y) end = (x,y) color=? draw(star,end) set color(col)