Object Oriented Programming Lecture 11: Polymorphism.

Slides:



Advertisements
Similar presentations
Containers CMPS Reusable containers Simple data structures in almost all nontrivial programs Examples: vectors, linked lists, stacks, queues, binary.
Advertisements

C++ Programming Languages
Lecture 10: Part 1: OO Issues CS 540 George Mason University.
Portability and Safety Mahdi Milani Fard Dec, 2006 Java.
Unified Modeling Language
1 G54PRG Programming Lecture 1 Amadeo Ascó Adam Moore 20 Object Oriented Theory II.
AbstractClassesInterfacesPolymorphism1 Abstract Classes, Interfaces, Polymorphism Barb Ericson Georgia Tech April 2010.
More about classes and objects Classes in Visual Basic.NET.
1 CS1001 Lecture Overview Homework 3 Homework 3 Project/Paper Project/Paper Object Oriented Design Object Oriented Design.
Lecture 27 Exam outline Boxing of primitive types in Java 1.5 Generic types in Java 1.5.
Review Amit Shabtay. March 3rd, 2004 Object Oriented Design Course 2 Review What have we done during the course? Where to learn more? What is for the.
C# Programming: From Problem Analysis to Program Design1 Advanced Object-Oriented Programming Features C# Programming: From Problem Analysis to Program.
OOP Spring 2007 – Recitation 71 Object Oriented Programming Spring 2006 Recitation 8.
OOP Etgar 2008 – Recitation 71 Object Oriented Programming Etgar 2008 Recitation 7.
Abstract Classes b b An abstract class is a placeholder in a class hierarchy that represents a generic concept b b An abstract class cannot be instantiated.
CS102--Object Oriented Programming Lecture 10: – Abstract Classes Copyright © 2008 Xiaoyan Li.
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,
INTRODUCTION TO JAVA PROGRAMMING Chapter 1. What is Computer Programming?
Comp 249 Programming Methodology Chapter 8 - Polymorphism Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University, Montreal,
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
OOPs Object oriented programming. Based on ADT principles  Representation of type and operations in a single unit  Available for other units to create.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
CONCEPTS OF OBJECT ORIENTED PROGRAMMING. Topics To Be Discussed………………………. Objects Classes Data Abstraction and Encapsulation Inheritance Polymorphism.
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.
Object Oriented Programming: Java Edition By: Samuel Robinson.
Programming With Java ICS201 University Of Ha’il1 Chapter 8 Polymorphism and Abstract Classes.
CSCI-383 Object-Oriented Programming & Design Lecture 13.
Polymorphism and Virtual Functions. Motivation Polymorphism is one of the fundamental mechanisms offered by OOP, and it is directly related to inheritance.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
OOP and Dynamic Method Binding Chapter 9. Object Oriented Programming Skipping most of this chapter Focus on 9.4, Dynamic method binding – Polymorphism.
Polymorphism. 3 main programming mechanisms that constitute OOP: 1. Encapsulation 2. Inheritance 3. Polymorphism.
Dale Roberts Object Oriented Programming using Java - Introduction Dale Roberts, Lecturer Computer Science, IUPUI Department.
Types in programming languages1 What are types, and why do we need them?
Lecture 4 Generic programming Advanced Java Programming 1 dr hab. Szymon Grabowski dr inż. Wojciech Bieniecki
: Maha Sabri Altememe Lecturer : Maha Sabri Altememe Lecture :1 1.
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.
OOPs Object oriented programming. Abstract data types  Representationof type and operations in a single unit  Available for other units to create variables.
Object Oriented Programming
1 COSC2007 Data Structures II Chapter 9 Class Relationships.
ISBN Object-Oriented Programming Chapter Chapter
Object Oriented Programming D. Place QUAKES, The University of Queensland.
Interfaces F What is an Interface? F Creating an Interface F Implementing an Interface F What is Marker Interface?
 2000 Prentice Hall, Inc. All rights reserved. Chapter 20 - Virtual Functions Outline 20.1Introduction 20.2Type Fields and switch Statements 20.3Virtual.
CSC241 Object-Oriented Programming (OOP) Lecture No. 17.
Session 7 More Implications of Inheritance & Chapter 5: Ball World Example.
C++ General Characteristics: - Mixed typing system - Constructors and destructors - Elaborate access controls to class entities.
CSC 205 Programming II Lecture 4 Abstract Class. The abstract keyword indicate that a class is not instantiable Defining a type which will be specialized.
CSCI-383 Object-Oriented Programming & Design Lecture 17.
Object Oriented Programming Lecture 2: BallWorld.
Learning Plan 6 Java Programming Intro to Object Oriented Programming.
Chapter 12: Support for Object- Oriented Programming Lecture # 18.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
DEVRY COMP 220 iLab 7 Polymorphism Lab Report and Source Code Check this A+ tutorial guideline at
Polymorphism in Methods
Programming in Java: lecture 7
Modern Programming Tools And Techniques-I
Sixth Lecture ArrayList Abstract Class and Interface
Done By: Ashlee Lizarraga Ricky Usher Jacinto Roches Eli Gomez
Interface Java 7 COMP T1.
Polymorphism.
Comp 249 Programming Methodology
Object-Oriented Programming (OOP) Lecture No. 28
Polymorphism CT1513.
Object Oriented Programming
Polymorphism Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition, by Kernighan.
Object-Oriented Programming Part 3 Bank Account Embezzling
Chapter 11 Class Inheritance
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:

Object Oriented Programming Lecture 11: Polymorphism

Polymorphism Sometimes we want to write general purpose code to manipulate items without too much regard as to what kind of items they are Example: General purpose list handling – List x; x.add(whatever);

Mechanisms Cheat on the type system (C/C++) Use object refs with run time typing (Java) Generics (C++, next release of Java) Dynamic Binding – Use Interfaces in Java – Use Abstract Classes and Methods in Java (Same technique with Virtual Functions in C++)

Cheating (Not Java) class List { public add(void *item); public void *head(); } List mylist; mylist.add(&whatever); Rectangle *r = (Rectangle *)mylist.head();

Object References (Java) class List { public add(Object item); public Object head(); } List mylist; mylist.add(any object); Rectangle r = (Rectangle )mylist.head();

Using References (Java) Supported by run time type checking, so that the process is type safe, but not checked at compile time. Result is that a program may fail at run time. Used in a series of utility classes (collection classes), see example of Vector later. Only works with objects – Cannot have a list, vector of integers (wrapper classes get around this limitation)

Generics (C++/Soon Java) class List { public void add(T item); public T head(); List mylist; mylist.add(r); Rectangle r = mylist.head();

Generics Fully type safe Static checking Allows homogeneous lists only (nearly) – Cheating allowed heterogeneous lists

Dynamic Binding The last crucial component of OOP – Encapsulation – Inheritance – Dynamic Binding

Examples The targets in the PinBallGame program of Budd’s Chapter 7 Shapes in a drawing program (classic) – Mouse10-15.java

Shape Program