SlideShare a Scribd company logo
1 of 13
Download to read offline
Introduction The Receiver Variable Reverse Polymorphism Pure Polymorphism Summary References
THE POLYMORPHIC VARIABLE
Muhammad Adil Raja
Roaming Researchers, Inc.
cbna
April 21, 2015
The Polymorphic Variable Roaming Researchers, Inc. cbna
Introduction The Receiver Variable Reverse Polymorphism Pure Polymorphism Summary References
OUTLINE I
INTRODUCTION
THE RECEIVER VARIABLE
REVERSE POLYMORPHISM
PURE POLYMORPHISM
SUMMARY
REFERENCES
The Polymorphic Variable Roaming Researchers, Inc. cbna
Introduction The Receiver Variable Reverse Polymorphism Pure Polymorphism Summary References
INTRODUCTION
A polymorphic variable is a variable that can hold values of
different types during the course of execution.
In this chapter we will consider:
Simple polymrophic variables.
The Receiver variable.
Reverse polymorphism.
Pure Polymorphism.
The Polymorphic Variable Roaming Researchers, Inc. cbna
Introduction The Receiver Variable Reverse Polymorphism Pure Polymorphism Summary References
SIMPLE POLYMORPHIC VARIABLES
We saw simple polymorphic variables earlier.
POLYMORPHIC VARIABLES
public class S o l i t a i r e {
. . .
static CardPile a l l P i l e s [ ] ;
. . .
public void paint ( Graphics g ) {
for ( int i = 0; i < 13; i ++)
a l l P i l e s [ i ] . display ( g ) ;
}
. . .
}
The variable was declared as CardPile, but actually held a
number of different types.
The Polymorphic Variable Roaming Researchers, Inc. cbna
Introduction The Receiver Variable Reverse Polymorphism Pure Polymorphism Summary References
THE RECEIVER VARIABLE
The most common polymorphic variable is the one that
holds the receiver during the execution of a method.
Call this in C++ and Java, self in Smalltalk and
Objective-C, current in Eiffel.
Holds the actual value (the dynamic class) during
execution, not the static class.
The Polymorphic Variable Roaming Researchers, Inc. cbna
Introduction The Receiver Variable Reverse Polymorphism Pure Polymorphism Summary References
THE RECEIVER VARIABLE IN FRAMEWORKS
The greatest power of the receiver variable comes in the
development of software frameworks.
In a framework, some methods are implemented in the
parent class and not overridden (called foundation
method), others are defined in the parent class, but
intended to be overridden (called deferred method).
Consider a class Window with subclasses TextWindow
and GraphicsWindow.
The combination of foundation and deferred methods allow
high level algorithms to be reused and specialized in new
situations.
The Polymorphic Variable Roaming Researchers, Inc. cbna
Introduction The Receiver Variable Reverse Polymorphism Pure Polymorphism Summary References
EXAMPLE REPAINTING WINDOW
EXAMPLE
class Window {
public void repaint ( ) {
/ / invoke the deferred method paint .
/ / Because the i m p l i c i t receiver , this ,
/ / i s polymorphic , the method from the
/ / c h i l d class w i l l be executed
paint ( graphicsContext ) ;
}
abstract public void paint ( Graphics g ) ; / / deferred
private Graphics graphicsContext ;
}
class GraphicsWindow extends Window {
public void paint ( Graphics g ) {
/ / do the appropriate painting job
}
}
Only the child class knows how to paint the window.
The receiver variable is responsible for remembering the
actual class of the receiver when executing the method inThe Polymorphic Variable Roaming Researchers, Inc. cbna
Introduction The Receiver Variable Reverse Polymorphism Pure Polymorphism Summary References
SELF AND SUPER
In Java and Smalltalk there is another pseudo-variable,
named super.
Super is like self, only when a message is given to super it
looks for the method in the parent class of the current
class.
Variable is called base in C#.
SELF AND SUPER
class Parent {
void exampleOne ( ) {
System . out . p r i n t l n ( " In parent method " ) ;
}
}
class Child extends Parent {
void exampleOne ( ) {
System . out . p r i n t l n ( " In c h i l d method " ) ;
super . exampleOne ( ) ;
}
}
The Polymorphic Variable Roaming Researchers, Inc. cbna
Introduction The Receiver Variable Reverse Polymorphism Pure Polymorphism Summary References
DOWNCAST (REVERSE POLYMORPHISM)
It is sometimes necessary to undo the assignment to a
polymorphic variable.
That is, to determine the variables true dynamic value, and
assign it to a variable of the appropriate type.
This process is termed down casting, or, since it is undoing
the polymorphic assignment, reverse polymorphism.
Various different syntaxes are used for this, see the book.
DOWNCASTING
Parent aVariable = . . . ;
Child aCard ;
i f ( aVariable instanceof Child )
aChild = ( Child ) aVariable ;
The Polymorphic Variable Roaming Researchers, Inc. cbna
Introduction The Receiver Variable Reverse Polymorphism Pure Polymorphism Summary References
PURE POLYMORPHISM I
A polymorphic method (also called pure polymorphism)
occurs when a polymorphic variable is used as an
argument.
Different effects are formed by using different types of
value.
EXAMPLE
The Polymorphic Variable Roaming Researchers, Inc. cbna
Introduction The Receiver Variable Reverse Polymorphism Pure Polymorphism Summary References
PURE POLYMORPHISM II
class StringBuffer {
String append ( Object value )
{ return append ( value . to St rin g ( ) ) ; }
. . .
}
Different objects implement toString differently, so the effects will vary depending upon the argument.
This example is from Smalltalk.
between : low and : high
^ ( low <= s e l f ) and : [ s e l f <= high ]
Different arguments will implement the relational test differently, so different effects can be achieved.
x between : $a and : $z
x between : 1 and : 100
x between : 3.14 and : 4.56
x between : " abc " and : " pdq "
x between : 10@5 and : 50@40
The Polymorphic Variable Roaming Researchers, Inc. cbna
Introduction The Receiver Variable Reverse Polymorphism Pure Polymorphism Summary References
SUMMARY
A polymorphic Variable is a variable that can reference
more than one type of object.
Polymorphic variables derive their power from interaction
with inheritance, overriding and substituion.
A common polymorphic variable is the implicit variable that
maintains the reciever during the execution of a method.
Downcasting is the undoing of a polymorphic assignment.
Pure polymorphism occurs when a polymorphic variable is
used as an argument.
The Polymorphic Variable Roaming Researchers, Inc. cbna
Introduction The Receiver Variable Reverse Polymorphism Pure Polymorphism Summary References
REFERENCES
Images and content for developing these slides have been
taken from the follwoing book with the permission of the
author.
An Introduction to Object Oriented Programming, Timothy
Budd.
This presentation is developed using Beamer:
Szeged, lily.
The Polymorphic Variable Roaming Researchers, Inc. cbna

More Related Content

Similar to The Polymorphic Variable

polymorphism.pdf
polymorphism.pdfpolymorphism.pdf
polymorphism.pdfriyawagh2
 
Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)Geekster
 
Lecture 6 inheritance
Lecture   6 inheritanceLecture   6 inheritance
Lecture 6 inheritancemanish kumar
 
principles of object oriented class design
principles of object oriented class designprinciples of object oriented class design
principles of object oriented class designNeetu Mishra
 
البرمجة الهدفية بلغة جافا - تعدد الأشكال
البرمجة الهدفية بلغة جافا - تعدد الأشكالالبرمجة الهدفية بلغة جافا - تعدد الأشكال
البرمجة الهدفية بلغة جافا - تعدد الأشكالMahmoud Alfarra
 
JAVA Polymorphism
JAVA PolymorphismJAVA Polymorphism
JAVA PolymorphismMahi Mca
 
9781439035665 ppt ch10
9781439035665 ppt ch109781439035665 ppt ch10
9781439035665 ppt ch10Terry Yoast
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...vekariyakashyap
 
البرمجة الهدفية بلغة جافا - الوراثة
البرمجة الهدفية بلغة جافا - الوراثةالبرمجة الهدفية بلغة جافا - الوراثة
البرمجة الهدفية بلغة جافا - الوراثةMahmoud Alfarra
 
What is java polymorphism and its types in java training?
What is  java polymorphism and its types in java training?What is  java polymorphism and its types in java training?
What is java polymorphism and its types in java training?kritikumar16
 

Similar to The Polymorphic Variable (20)

polymorphism.pdf
polymorphism.pdfpolymorphism.pdf
polymorphism.pdf
 
Overriding
OverridingOverriding
Overriding
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)
 
Lecture 6 inheritance
Lecture   6 inheritanceLecture   6 inheritance
Lecture 6 inheritance
 
principles of object oriented class design
principles of object oriented class designprinciples of object oriented class design
principles of object oriented class design
 
Overloading
OverloadingOverloading
Overloading
 
OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)
 
البرمجة الهدفية بلغة جافا - تعدد الأشكال
البرمجة الهدفية بلغة جافا - تعدد الأشكالالبرمجة الهدفية بلغة جافا - تعدد الأشكال
البرمجة الهدفية بلغة جافا - تعدد الأشكال
 
JAVA Polymorphism
JAVA PolymorphismJAVA Polymorphism
JAVA Polymorphism
 
07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
 
9781439035665 ppt ch10
9781439035665 ppt ch109781439035665 ppt ch10
9781439035665 ppt ch10
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
 
8 polymorphism
8 polymorphism8 polymorphism
8 polymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Generics
GenericsGenerics
Generics
 
البرمجة الهدفية بلغة جافا - الوراثة
البرمجة الهدفية بلغة جافا - الوراثةالبرمجة الهدفية بلغة جافا - الوراثة
البرمجة الهدفية بلغة جافا - الوراثة
 
Oop lecture 06
Oop lecture 06Oop lecture 06
Oop lecture 06
 
What is java polymorphism and its types in java training?
What is  java polymorphism and its types in java training?What is  java polymorphism and its types in java training?
What is java polymorphism and its types in java training?
 

More from adil raja

A Software Requirements Specification
A Software Requirements SpecificationA Software Requirements Specification
A Software Requirements Specificationadil raja
 
NUAV - A Testbed for Development of Autonomous Unmanned Aerial Vehicles
NUAV - A Testbed for Development of Autonomous Unmanned Aerial VehiclesNUAV - A Testbed for Development of Autonomous Unmanned Aerial Vehicles
NUAV - A Testbed for Development of Autonomous Unmanned Aerial Vehiclesadil raja
 
DevOps Demystified
DevOps DemystifiedDevOps Demystified
DevOps Demystifiedadil raja
 
On Research (And Development)
On Research (And Development)On Research (And Development)
On Research (And Development)adil raja
 
Simulators as Drivers of Cutting Edge Research
Simulators as Drivers of Cutting Edge ResearchSimulators as Drivers of Cutting Edge Research
Simulators as Drivers of Cutting Edge Researchadil raja
 
The Knock Knock Protocol
The Knock Knock ProtocolThe Knock Knock Protocol
The Knock Knock Protocoladil raja
 
File Transfer Through Sockets
File Transfer Through SocketsFile Transfer Through Sockets
File Transfer Through Socketsadil raja
 
Remote Command Execution
Remote Command ExecutionRemote Command Execution
Remote Command Executionadil raja
 
CMM Level 3 Assessment of Xavor Pakistan
CMM Level 3 Assessment of Xavor PakistanCMM Level 3 Assessment of Xavor Pakistan
CMM Level 3 Assessment of Xavor Pakistanadil raja
 
Data Warehousing
Data WarehousingData Warehousing
Data Warehousingadil raja
 
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...adil raja
 
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...adil raja
 
Real-Time Non-Intrusive Speech Quality Estimation for VoIP
Real-Time Non-Intrusive Speech Quality Estimation for VoIPReal-Time Non-Intrusive Speech Quality Estimation for VoIP
Real-Time Non-Intrusive Speech Quality Estimation for VoIPadil raja
 
ULMAN GUI Specifications
ULMAN GUI SpecificationsULMAN GUI Specifications
ULMAN GUI Specificationsadil raja
 
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...adil raja
 
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...adil raja
 

More from adil raja (20)

ANNs.pdf
ANNs.pdfANNs.pdf
ANNs.pdf
 
A Software Requirements Specification
A Software Requirements SpecificationA Software Requirements Specification
A Software Requirements Specification
 
NUAV - A Testbed for Development of Autonomous Unmanned Aerial Vehicles
NUAV - A Testbed for Development of Autonomous Unmanned Aerial VehiclesNUAV - A Testbed for Development of Autonomous Unmanned Aerial Vehicles
NUAV - A Testbed for Development of Autonomous Unmanned Aerial Vehicles
 
DevOps Demystified
DevOps DemystifiedDevOps Demystified
DevOps Demystified
 
On Research (And Development)
On Research (And Development)On Research (And Development)
On Research (And Development)
 
Simulators as Drivers of Cutting Edge Research
Simulators as Drivers of Cutting Edge ResearchSimulators as Drivers of Cutting Edge Research
Simulators as Drivers of Cutting Edge Research
 
The Knock Knock Protocol
The Knock Knock ProtocolThe Knock Knock Protocol
The Knock Knock Protocol
 
File Transfer Through Sockets
File Transfer Through SocketsFile Transfer Through Sockets
File Transfer Through Sockets
 
Remote Command Execution
Remote Command ExecutionRemote Command Execution
Remote Command Execution
 
Thesis
ThesisThesis
Thesis
 
CMM Level 3 Assessment of Xavor Pakistan
CMM Level 3 Assessment of Xavor PakistanCMM Level 3 Assessment of Xavor Pakistan
CMM Level 3 Assessment of Xavor Pakistan
 
Data Warehousing
Data WarehousingData Warehousing
Data Warehousing
 
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
 
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
 
Real-Time Non-Intrusive Speech Quality Estimation for VoIP
Real-Time Non-Intrusive Speech Quality Estimation for VoIPReal-Time Non-Intrusive Speech Quality Estimation for VoIP
Real-Time Non-Intrusive Speech Quality Estimation for VoIP
 
VoIP
VoIPVoIP
VoIP
 
ULMAN GUI Specifications
ULMAN GUI SpecificationsULMAN GUI Specifications
ULMAN GUI Specifications
 
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
 
ULMAN-GUI
ULMAN-GUIULMAN-GUI
ULMAN-GUI
 
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
 

Recently uploaded

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 

Recently uploaded (20)

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 

The Polymorphic Variable

  • 1. Introduction The Receiver Variable Reverse Polymorphism Pure Polymorphism Summary References THE POLYMORPHIC VARIABLE Muhammad Adil Raja Roaming Researchers, Inc. cbna April 21, 2015 The Polymorphic Variable Roaming Researchers, Inc. cbna
  • 2. Introduction The Receiver Variable Reverse Polymorphism Pure Polymorphism Summary References OUTLINE I INTRODUCTION THE RECEIVER VARIABLE REVERSE POLYMORPHISM PURE POLYMORPHISM SUMMARY REFERENCES The Polymorphic Variable Roaming Researchers, Inc. cbna
  • 3. Introduction The Receiver Variable Reverse Polymorphism Pure Polymorphism Summary References INTRODUCTION A polymorphic variable is a variable that can hold values of different types during the course of execution. In this chapter we will consider: Simple polymrophic variables. The Receiver variable. Reverse polymorphism. Pure Polymorphism. The Polymorphic Variable Roaming Researchers, Inc. cbna
  • 4. Introduction The Receiver Variable Reverse Polymorphism Pure Polymorphism Summary References SIMPLE POLYMORPHIC VARIABLES We saw simple polymorphic variables earlier. POLYMORPHIC VARIABLES public class S o l i t a i r e { . . . static CardPile a l l P i l e s [ ] ; . . . public void paint ( Graphics g ) { for ( int i = 0; i < 13; i ++) a l l P i l e s [ i ] . display ( g ) ; } . . . } The variable was declared as CardPile, but actually held a number of different types. The Polymorphic Variable Roaming Researchers, Inc. cbna
  • 5. Introduction The Receiver Variable Reverse Polymorphism Pure Polymorphism Summary References THE RECEIVER VARIABLE The most common polymorphic variable is the one that holds the receiver during the execution of a method. Call this in C++ and Java, self in Smalltalk and Objective-C, current in Eiffel. Holds the actual value (the dynamic class) during execution, not the static class. The Polymorphic Variable Roaming Researchers, Inc. cbna
  • 6. Introduction The Receiver Variable Reverse Polymorphism Pure Polymorphism Summary References THE RECEIVER VARIABLE IN FRAMEWORKS The greatest power of the receiver variable comes in the development of software frameworks. In a framework, some methods are implemented in the parent class and not overridden (called foundation method), others are defined in the parent class, but intended to be overridden (called deferred method). Consider a class Window with subclasses TextWindow and GraphicsWindow. The combination of foundation and deferred methods allow high level algorithms to be reused and specialized in new situations. The Polymorphic Variable Roaming Researchers, Inc. cbna
  • 7. Introduction The Receiver Variable Reverse Polymorphism Pure Polymorphism Summary References EXAMPLE REPAINTING WINDOW EXAMPLE class Window { public void repaint ( ) { / / invoke the deferred method paint . / / Because the i m p l i c i t receiver , this , / / i s polymorphic , the method from the / / c h i l d class w i l l be executed paint ( graphicsContext ) ; } abstract public void paint ( Graphics g ) ; / / deferred private Graphics graphicsContext ; } class GraphicsWindow extends Window { public void paint ( Graphics g ) { / / do the appropriate painting job } } Only the child class knows how to paint the window. The receiver variable is responsible for remembering the actual class of the receiver when executing the method inThe Polymorphic Variable Roaming Researchers, Inc. cbna
  • 8. Introduction The Receiver Variable Reverse Polymorphism Pure Polymorphism Summary References SELF AND SUPER In Java and Smalltalk there is another pseudo-variable, named super. Super is like self, only when a message is given to super it looks for the method in the parent class of the current class. Variable is called base in C#. SELF AND SUPER class Parent { void exampleOne ( ) { System . out . p r i n t l n ( " In parent method " ) ; } } class Child extends Parent { void exampleOne ( ) { System . out . p r i n t l n ( " In c h i l d method " ) ; super . exampleOne ( ) ; } } The Polymorphic Variable Roaming Researchers, Inc. cbna
  • 9. Introduction The Receiver Variable Reverse Polymorphism Pure Polymorphism Summary References DOWNCAST (REVERSE POLYMORPHISM) It is sometimes necessary to undo the assignment to a polymorphic variable. That is, to determine the variables true dynamic value, and assign it to a variable of the appropriate type. This process is termed down casting, or, since it is undoing the polymorphic assignment, reverse polymorphism. Various different syntaxes are used for this, see the book. DOWNCASTING Parent aVariable = . . . ; Child aCard ; i f ( aVariable instanceof Child ) aChild = ( Child ) aVariable ; The Polymorphic Variable Roaming Researchers, Inc. cbna
  • 10. Introduction The Receiver Variable Reverse Polymorphism Pure Polymorphism Summary References PURE POLYMORPHISM I A polymorphic method (also called pure polymorphism) occurs when a polymorphic variable is used as an argument. Different effects are formed by using different types of value. EXAMPLE The Polymorphic Variable Roaming Researchers, Inc. cbna
  • 11. Introduction The Receiver Variable Reverse Polymorphism Pure Polymorphism Summary References PURE POLYMORPHISM II class StringBuffer { String append ( Object value ) { return append ( value . to St rin g ( ) ) ; } . . . } Different objects implement toString differently, so the effects will vary depending upon the argument. This example is from Smalltalk. between : low and : high ^ ( low <= s e l f ) and : [ s e l f <= high ] Different arguments will implement the relational test differently, so different effects can be achieved. x between : $a and : $z x between : 1 and : 100 x between : 3.14 and : 4.56 x between : " abc " and : " pdq " x between : 10@5 and : 50@40 The Polymorphic Variable Roaming Researchers, Inc. cbna
  • 12. Introduction The Receiver Variable Reverse Polymorphism Pure Polymorphism Summary References SUMMARY A polymorphic Variable is a variable that can reference more than one type of object. Polymorphic variables derive their power from interaction with inheritance, overriding and substituion. A common polymorphic variable is the implicit variable that maintains the reciever during the execution of a method. Downcasting is the undoing of a polymorphic assignment. Pure polymorphism occurs when a polymorphic variable is used as an argument. The Polymorphic Variable Roaming Researchers, Inc. cbna
  • 13. Introduction The Receiver Variable Reverse Polymorphism Pure Polymorphism Summary References REFERENCES Images and content for developing these slides have been taken from the follwoing book with the permission of the author. An Introduction to Object Oriented Programming, Timothy Budd. This presentation is developed using Beamer: Szeged, lily. The Polymorphic Variable Roaming Researchers, Inc. cbna