Polymorphism What is it, why it is needed? Dynamic binding Sorting and searching.

Slides:



Advertisements
Similar presentations
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Advertisements

Overview of Data Structures and Algorithms
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.
1 l Inheritance Basics l Programming with Inheritance l Dynamic Binding and Polymorphism Inheritance.
Chapter 1 OO using C++. Abstract Data Types Before we begin we should know how to accomplish the goal of the program We should know all the input and.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Chapter 9: Polymorphism Coming up: Binding.
Chapter 9 Polymorphism. © 2004 Pearson Addison-Wesley. All rights reserved9-2 Polymorphism Polymorphism (having many forms) is an object- oriented concept.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Abstract Classes.
Inheritance and Polymorphism Recitation 04/10/2009 CS 180 Department of Computer Science, Purdue University.
ECE122 L22: Polymorphism Using Inheritance April 26, 2007 ECE 122 Engineering Problem Solving with Java Lecture 22 Polymorphism using Inheritance.
Static and Dynamic Behavior Fall 2005 OOPD John Anthony.
Chapter 9 Polymorphism 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All rights reserved.
CS 106 Introduction to Computer Science I 04 / 21 / 2008 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 04 / 28 / 2010 Instructor: Michael Eckmann.
Aalborg Media Lab 15-Jul-15 Polymorphism Lecture 12 Chapter 9.
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.
Chapter 15 – Inheritance, Virtual Functions, and Polymorphism
1 Polymorphism  A reference can be polymorphic, which can be defined as "having many forms" obj.doIt();  This line of code might execute different methods.
Part 2.  Predefined  User defined  //exclusive to c++  / //c specific.
Chapter 9 Polymorphism. © 2004 Pearson Addison-Wesley. All rights reserved Polymorphism Polymorphism is an object-oriented concept that allows.
Chapter 9: Polymorphism Coming up: Creating Objects Revisited.
Object Oriented Programming with C++/ Session 6 / 1 of 44 Multiple Inheritance and Polymorphism Session 6.
Chapter 9 Polymorphism. © 2004 Pearson Addison-Wesley. All rights reserved Polymorphism Polymorphism is an object-oriented concept that allows.
Chapter 9 Polymorphism. Chapter Scope The role of polymorphism Dynamic binding Using inheritance for polymorphism Exploring Java interfaces in more detail.
© 2004 Pearson Addison-Wesley. All rights reserved April 17, 2006 Polymorphism (part 2) ComS 207: Programming I (in Java) Iowa State University, SPRING.
Lecture 10 – Polymorphism Nancy Harris with additional slides Professor Adams from Lewis & Bernstein.
CS221 - Computer Science II Polymorphism 1. CS221 - Computer Science II Polymorphism 2 Outline  Explanation of polymorphism.  Using polymorphism to.
OOP: Encapsulation,Abstraction & Polymorphism. What is Encapsulation Described as a protective barrier that prevents the code and data being randomly.
CS 106 Introduction to Computer Science I 04 / 23 / 2010 Instructor: Michael Eckmann.
Chapter 9 Polymorphism. © 2004 Pearson Addison-Wesley. All rights reserved Polymorphism Polymorphism is an object-oriented concept that allows.
1 Chapter 9a Abstract Classes & Dynamic Binding. 2 Abstract Classes All classes so far have been concrete classes –Classes that can be used to create.
 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Polymorphism.
CS 106 Introduction to Computer Science I 04 / 18 / 2008 Instructor: Michael Eckmann.
© 2004 Pearson Addison-Wesley. All rights reserved April 14, 2006 Polymorphism ComS 207: Programming I (in Java) Iowa State University, SPRING 2006 Instructor:
CS212: Object Oriented Analysis and Design Lecture 16: Runtime Polymorphism.
Interfaces F What is an Interface? F Creating an Interface F Implementing an Interface F What is Marker Interface?
Polymorphism and Virtual Functions One name many shapes behaviour Unit - 07.
COMP Inheritance and Polymorphism Yi Hong June 09, 2015.
Lecture 10 – Polymorphism Nancy Harris with additional slides Professor Adams from Lewis & Bernstein.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Chapter 5: Enhancing Classes
Introduction to Computers Computer Generations
Polymorphism November 27, 2006 ComS 207: Programming I (in Java)
Chapter 9 Polymorphism.
Inheritance and Polymorphism
CS212: Object Oriented Analysis and Design
Polymorphism.
Interfaces and Inheritance
Object-Oriented Programming: Polymorphism
Object Oriented Programming
Designing for Inheritance
Polymorphism Lec
Inheritance Basics Programming with Inheritance
Polymorphism CT1513.
Object Oriented Programming
Computer Programming with JAVA
Pointers Dr. Bhargavi Goswami Department of Computer Science
Polymorphism CT1513.
1.4 ทบทวน JAVA OO Programming Concepts Declaring and Creating Objects
Chapter 9 Polymorphism.
COP 3330 Object-oriented Programming in C++
Chapter 11 Class Inheritance
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.
Programming in C# CHAPTER 5 & 6
Presentation transcript:

Polymorphism What is it, why it is needed? Dynamic binding Sorting and searching

ChessPiece bishop; bishop Object : instance of ChessPiece “having many forms” Polymorphic reference can refer to different types of objects at different points in time

Obj.doIt(); //if obj is polymorphic In the loop In a method Commitment is made to execute certain code to carry out a method invocation : binding a method invocation to a method definition Compile time binding vs. run time binding polymorphic reference late binding / dynamic binding via inheritance / interface

Polymorphism via Inheritance Class name reference variable; Reference variable can refer to any object of that class related to its declared type by inheritance mammal pet; horse secretariat = new Horse(); pet = secretariat; animal creature = new Horse();creature.move(); Object reference?

Firm has 3 different staff members Volunteer, Employee( Executive, Hourly) Employee: name address phone Employee: + ssn payrate Executive: + bonus Houlry = - bonus + hours worked

Selection Insertion quick

temp = myarray[2]; myarray[2] = myarray[1]; myarray[1] = temp; temp = myarray[3]; Myarray[1]=myarray[0]; myarray[2] = myarray[1]; myarray[3] = myarray[2]; Myarray[0] = temp

Sort and search - Insertion, selection, quick, merge - Linear search, binary search