Polymorphism Encapsulation Inheritance

Slides:



Advertisements
Similar presentations
2006 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Polymorphism.
Advertisements

Inheritance. Many objects have a hierarchical relationship –Examples: zoo, car/vehicle, card game, airline reservation system Inheritance allows software.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 15: Polymorphism,
Session 07: C# OOP 4 Review of: Inheritance and Polymorphism. Static and dynamic type of an object. Abstract Classes. Interfaces. FEN AK - IT:
Inheritance. In this chapter, we will cover: The concept of inheritance Extending classes Overriding superclass methods Working with superclasses that.
© Copyright Eliyahu Brutman Programming Techniques Course Version 1.0.
1 Evan Korth New York University abstract classes and casting Professor Evan Korth New York University.
12/08/08MET CS Fall Polymorphism 10. Polymorphism Goal: Goal: Create methods that can be invoked with all object types, base as well as.
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,
Abstract Classes An abstract class is a base class that will never have an object instantiated from it. –Abstract classes are used only for inheritance,
Virtual Functions Junaed Sattar November 10, 2008 Lecture 10.
Computer Science and Software Engineering University of Wisconsin - Platteville 7. Inheritance and Polymorphism Yan Shi CS/SE 2630 Lecture Notes.
Chapter 4 Inheritance Bernard Chen Spring Objective IS-A relationships and the allowable changes for derived classes The concept of polymorphism.
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
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.
1 Virtual Functions and Polymorphism Chapter What You Will Learn What is polymorphism? How to declare and use virtual functions for abstract classes.
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.
Polymorphism. Introduction ‘one name multiple forms’ Implemented using overloaded functions and operators Early binding or static binding or static linking.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
1 Abstract Class There are some situations in which it is useful to define base classes that are never instantiated. Such classes are called abstract classes.
Day Virtual versus static methods. 2. Polymorphism 3. Detailed worked example. 4. Abstract classes.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Unit IV Unit IV: Virtual functions concepts, Abstracts classes & pure virtual functions. Virtual base classes, Friend functions, Static functions, Assignment.
OOP and Dynamic Method Binding Chapter 9. Object Oriented Programming Skipping most of this chapter Focus on 9.4, Dynamic method binding – Polymorphism.
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
Polymorphism Polymorphism occurs with objects instantiated from a set of classes related by inheritance to the same ancestor class. –Each class provides.
C/C++ 3 Yeting Ge. Static variables Static variables is stored in the static storage. Static variable will be initialized once. 29.cpp 21.cpp.
Session 04 Module 8: Abstract classes and Interface Module 9: Properties and Indexers.
Module 10: Inheritance in C#. Overview Deriving Classes Implementing Methods Using Sealed Classes Using Interfaces Using Abstract Classes.
Java Programming Dr. Randy Kaplan. Abstract Classes and Methods.
Object Oriented Programming
1 Advanced Programming Inheritance (2). 2 Inheritance Inheritance allows a software developer to derive a new class from an existing one The existing.
Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming.
1 Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Recap Introduction to Inheritance Inheritance in C++ IS-A Relationship Polymorphism in Inheritance Classes in Inheritance Visibility Rules Constructor.
Inheritance ndex.html ndex.htmland “Java.
Object Oriented Programming in C++ Chapter 7 Dynamic Binding.
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.
Polymorphism Lecture - 9.
COP INTERMEDIATE JAVA Inheritance, Polymorphism, Interfaces.
Inheritance - 3. Virtual Functions Functions defined as virtual are ones that the base expects its derived classes may redefine. Functions defined as.
 2006 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Polymorphism.
C++ General Characteristics: - Mixed typing system - Constructors and destructors - Elaborate access controls to class entities.
C++ How to Program, 7/e. © by Pearson Education, Inc. All Rights Reserved.2.
Chapter 12: Support for Object- Oriented Programming Lecture # 18.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Polymorphism in Methods
Ch 10- Advanced Object-Oriented Programming Features
7. Inheritance and Polymorphism
Inheritance and Big O And your first reading assignment
Class A { public : Int x; A()
Types of Programming Languages
Polymorphism Lec
Abstract Classes AKEEL AHMED.
Polymorphism CT1513.
Object Oriented Programming
Polymorphism Polymorphism
Polymorphism Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition, by Kernighan.
Virtual Functions Polymorphism is supported by C++ both at compile time and at run time. Compile-time polymorphism is achieved by overloading functions.
Java Inheritance.
COP 3330 Object-oriented Programming in C++
Chapter 11 Class Inheritance
Binding 10: Binding Programming C# © 2003 DevelopMentor, Inc.
C++ Polymorphism Reference and pointer implicit type casting
Inheritance Lakshmish Ramaswamy.
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.
Computer Science II for Majors
Presentation transcript:

Polymorphism Encapsulation Inheritance Polymorphism (from the Greek meaning "having multiple forms") The ability for different objects derived from a common base object to respond to the same stimuli in a completely different ways.

Examples Pledge: “I, (state your name), do solemnly swear….” UPE (Upsilon Pi Epsilon) pledge: "I ( state your name ), … having heard and understood ... the purposes and tenets of Upsilon Pi Epsilon ... do solemnly pledge, ... always to respect and promote ... the aims and ideals of this Society.” Programing examples

Virtual Methods Different derived classes respond to the same request in different ways. A class provides virtual method, which allows any class derived from it to respond differently to the same request : via override the virtual method in the derived class, and then call the method in the base class Virtual methods virtual void speak() {}; Pure virtual method virtual void speak() = 0;

Run-time Binding Virtual methods override by a method in a derived class virtual void speak() override {}; Compare to general method override Both require identical signature Static binding (binding to the type that the method is called) in general method override vs, run-time binding in the virtual method case (derived class type’s method overrides at the time of instantiate)

Which function to call? ClassA^ a=gcnew ClassB(); a->f(); Example: ClassB derives from ClassA, and so on… ClassA has a method f(); ClassB, ClassC, ClassD all implement own f(); Object ClassA ClassA^ a=gcnew ClassB(); a->f(); ClassB ClassC C++: virtual method ClassD

Abstract ref class An incomplete definition of a ref class that has at least one pure virtual member method; Cannot instantiate an object of it; A derived class of it must implement the pure virtual function, (or, it becomes abstract)

C++ Example How to check the earnings of different employee types? Object first, last, Earnings, ToString Employee Boss CommissionWorker PieceWorker HourlyWorker salary, Earnings, ToString wagePerPiece, quantity Earnings, ToString

Applications

Summary Although virtual functions of a base class are called within a framework, the actual functions to be called at run time are that of the actual class derived from the base class. Only base classes are needed to define a framework. Dynamic Binding versus Static Binding