Inheritance Examples.

Slides:



Advertisements
Similar presentations
Under the Hood of Polymorphism CS-2303, C-Term Under the Hood of Polymorphism CS-2303 System Programming Concepts (Slides include materials from.
Advertisements

1 Chapter 6: Extending classes and Inheritance. 2 Basics of Inheritance One of the basic objectives of Inheritance is code reuse If you want to extend.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 15: Polymorphism,
Inheritance Java permits you to use your user defined classes to create programs using inheritance.
Advanced Programming in Java
Sadegh Aliakbary Sharif University of Technology Fall 2010.
© 2006 Pearson Addison-Wesley. All rights reserved9 A-1 Chapter 9 Advanced Java Topics (inheritance review + Java generics)
Inheritance and object compatibility Object type compatibility An instance of a subclass can be used instead of an instance of the superclass, but not.
Patterns Lecture 2. Singleton Ensure a class only has one instance, and provide a global point of access to it.
C++ Training Datascope Lawrence D’Antonio Lecture 3 An Overview of C++
CPSC150 Interfaces Chapter CPSC150 Inheritance Review No different than any other class. Has no access to or information about subclasses class.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 24: Dynamic Binding COMP 144 Programming Language Concepts Spring 2002 Felix Hernandez-Campos.
© 2006 Pearson Addison-Wesley. All rights reserved9 A-1 Chapter 9 Advanced Java Topics CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2007.
C++ Polymorphism Systems Programming. Systems Programming: Polymorphism 2   Polymorphism Examples   Relationships Among Objects in an Inheritance.
PolymorphismCS-2303, C-Term Polymorphism Hugh C. Lauer Adjunct Professor (Slides include materials from The C Programming Language, 2 nd edition,
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 2: Modelling.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Learners Support Publications Pointers, Virtual Functions and Polymorphism.
Dr. Ahmad R. Hadaegh A.R. Hadaegh California State University San Marcos (CSUSM) Page 1 Virtual Functions Polymorphism Abstract base classes.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Recitation 4 Abstract classes, Interfaces. A Little More Geometry! Abstract Classes Shape x ____ y ____ Triangle area() base____ height ____ Circle area()
OOP and Dynamic Method Binding Chapter 9. Object Oriented Programming Skipping most of this chapter Focus on 9.4, Dynamic method binding – Polymorphism.
Inheritance in the Java programming language J. W. Rider.
Object Oriented Programming Lecture 11: Polymorphism.
Chapter 10 Inheritance and Polymorphism
Inheritance Revisited Other Issues. Multiple Inheritance Also called combination--not permitted in Java, but is used in C++ Also called combination--not.
(1) ICS 313: Programming Language Theory Chapter 12: Object Oriented Programming.
CMSC 202 Lesson 18 Polymorphism 1. Warmup What errors are present in the following hierarchy? Assume GetCurrentTime() and RingBell() are defined elsewhere.
ISBN Object-Oriented Programming Chapter Chapter
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Class Inheritance SWE 344 Internet Protocols & Client Server Programming.
OOPS CONCEPT.  OOPS  Benefits of OOPs  OOPs Principles  Class  Object Objectives.
1 Lecture 23: Dynamic Binding (Section ) CSCI 431 Programming Languages Fall 2002 A compilation of material developed by Felix Hernandez-Campos.
Polymorphism and Virtual Functions One name many shapes behaviour Unit - 07.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 20 - Virtual Functions Outline 20.1Introduction 20.2Type Fields and switch Statements 20.3Virtual.
Testing in OO Environment The reasons for testing is not any different for any of the design and implementation methodologies, including OO methodology.
CS 350 – Software Design The Decorator Pattern – Chapter 17 In this chapter we expand our e-commerce case study and learn how to use the Decorator Pattern.
Lecture 2 Intro. To Software Engineering and Object-Oriented Programming (2/2)
Polymorphism Lecture - 9.
C++ General Characteristics: - Mixed typing system - Constructors and destructors - Elaborate access controls to class entities.
CSCI-383 Object-Oriented Programming & Design Lecture 17.
Learning Plan 6 Java Programming Intro to Object Oriented Programming.
Chapter 12: Support for Object- Oriented Programming Lecture # 18.
Inheritance New class derived from existing class Software engineering technique Software reuse : faster, easier, cheaper Parent class (supper class):
DEVRY COMP 220 iLab 7 Polymorphism Lab Report and Source Code Check this A+ tutorial guideline at
Polymorphism.
Lecture 12 Inheritance.
Interfaces.
Inheritance and Polymorphism
OOP What is problem? Solution? OOP
Object-Orientated Programming
Types of Programming Languages
ATS Application Programming: Java Programming
Object Oriented Analysis and Design
Advanced Java Topics Chapter 9
Polymorphism 1 CMSC 202.
Object Oriented Programming
Object Oriented Programming
“Under the Hood” of Polymorphism
Polymorphism Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition, by Kernighan.
Chapter 9 Carrano Chapter 10 Small Java
VIRTUAL FUNCTIONS RITIKA SHARMA.
Chapter 11 Class Inheritance
Ninth step for Learning C++ Programming
Jim Fawcett CSE687 – Object Oriented Design Spring 2014
The Object Paradigm Classes – Templates for creating objects
C++ Polymorphism Reference and pointer implicit type casting
C++ Object Oriented 1.
Static Binding Static binding chooses the function in the class of the base class pointer, ignoring any versions in the class of the object actually.
Presentation transcript:

Inheritance Examples

Real-world Examples: Animals Dog Cat Source code: http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming

Example #2: Timepieces

Multiple inheritance A derived class can have more than one base class Java does not support it – uses “interface” instead.

Example #3: Shapes Basic Shape Circle Polygon Ellipse Square Rectangle Hexagon

Example #4: Wireless Telephony Mobile initiated message Registration Call Processing SMS Origination Page Response

Value of inheritance? Helps us to break software into manageable pieces Existing classes can be morphed to design new classes – code reuse Enables us to group different types of objects together and do some action on all of them.

Inheritance Examples in Java and C++

Back to Example #1: Animals Dog Cat Want to group them together & make them talk?

Concepts Static binding vs. dynamic binding Polymorphism using virtual methods Abstract base class Ability of base class pointers to point to derived class objects

Add Human? Animal Human Dog Cat Want to group them together & make them talk?

C++ AnimalActions Animal Human Dog Cat

Java: Interface AnimalActions Animal Human Dog Cat

Example from Wiki: Bad use of Inheritance Whistler Parrot Human

Example from Wiki Whistler Human Parrot

Concepts Interface

C++ Animal AnimalActions Dog Cat Human

Java: Interface AnimalActions Animal Human Dog Cat

Inheritance Examples in Java and C++

References http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming - Animals : Inheritance coding examples in Java/C++/… http://en.wikipedia.org/wiki/Interface_%28Java%29 – Java Interfaces