SlideShare a Scribd company logo
1 of 20
Download to read offline
STATIC AND DYNAMIC BEHAVIOR
Muhammad Adil Raja
Roaming Researchers, Inc.
cbna
April 19, 2015
Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 1 / 20
OUTLINE I
1 INTRODUCTION
2 STATIC AND DYNAMIC TYPING
3 REFERENCES
Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 2 / 20
Introduction
INTRODUCTION
How differences in static and dynamic features effect
object-oriented programming languages.
Static versus Dynamic Typing.
Static and Dynamic Classes in Statically Typed Languages.
Static and Dynamic Method Binding in Statically Typed
Languages.
Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 3 / 20
Static and Dynamic Typing
WHAT DO THE TERMS STATIC AND DYNAMIC MEAN?
MESSAGE SYNTAX
In Programming languages: Static almost always means fixed or
bound at compile time, and cannot thereafter be changed.
Dynamic almost always means not fixed or bound until run time,
and therefore can change during the course of execution.
Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 4 / 20
Static and Dynamic Typing
STATIC AND DYNAMIC TYPING
In a statically typed programming language (Java or Pascal), for
example, variables have declared types – fixed at compile time.
In a dynamically typed programming language (Smalltalk or
CLOS), a variable is just a name.
Types are associated with values, not variables.
A variable can hold different types during the course of execution.
Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 5 / 20
Static and Dynamic Typing
ARGUMENTS FOR THE AGAINST
Static and Dynamically typed languages have existed as long as
there have been programming languages.
Arguments for and against:
Static typing allows better error detection, more work at compile
time and hence faster execution time.
Dynamic typing allows greater flexibility, easier to write (for
example, no declaration statements).
Both arguments have some validity, and hence both types of
languages will continue to exist in the future.
Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 6 / 20
Static and Dynamic Typing
THE POLYMORPHIC VARIABLE
The addition of object-oriented ideas in a statically typed
languages adds a new twist.
Recall the argument for substitution: an instance of a child class
should be allowed to be assigned to a variable of the parent class:
THE POLYMORPHIC VARIABLE
var
pet : Mammal;
f i d o : Dog ;
f e l i c e : Cat ;
begin
pet := f i d o ; / / legal
pet := f e l i c e ; / / legal
f i d o := pet ; / / not legal !
Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 7 / 20
Static and Dynamic Typing
STATIC CLASS AND DYNAMIC CLASS
In a statically typed language we say the class of the declaration
is the static class for the variable, while the class of the value it
currently holds is the dynamic class.
Most statically typed OO languages constrain the dynamic class
to be a child class of the static class.
STATIC VS DYNAMIC
var
pet : Mammal;
f i d o : Dog
begin
pet := f i d o ; / / s t a t i c class i s Mammal, dynamic class i s Dog
end ;
Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 8 / 20
Static and Dynamic Typing
IMPORTANCE OF STATIC CLASS
In a statically typed object-oriented language, the legality of a
message is determined at compile time, based on the static class.
A message can produce a compile error, even if no run-time error
could possibly arize:
class Mammal { }
class Dog extends Mammal {
void speak ( ) { System . out . p r i n t l n ( " woof " ) ; }
}
Mammal pet = new Dog ;
pet . speak ( ) ; / / w i l l generate error , Mammals don ’ t speak
Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 9 / 20
Static and Dynamic Typing
REVERSE POLYMORPHISM
Polymorphism says we can assign a value from a child class to an
instance of the parent class, but can this assignment then be
reversed?
Under what conditions?
This is known as the problem of reverse polymorphism.
REVERSE POLYMORPHISM
var
pet : Mammal;
f i d o : Dog ;
f e l i c e : Cat ;
begin
pet := f i d o ; / / legal
f i d o := pet ; / / i s t h i s legal ?
end ;
Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 10 / 20
Static and Dynamic Typing
TWO ASPECTS OF REVERSE POLYMORPHISM
There are two specific problems associated with the question of
reverse polymorphism.
The problem of identity – can I tell if a value declared as an
instance of a parent class actually holds a value from a subclass.
The task of assignment – can I then assign the value from the
parent class to a variable declared as the subclass.
In some languages mechanisms are provided to address these
two problems together, while in other languages they are
separated.
Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 11 / 20
Static and Dynamic Typing
THE CONTAINER PROBLEM
The task of reverse polymorphism is often encountered in
connection with a collection of values - we have a list of items from
the parent class (say a list of Mammals), and when we extract a
value we need to know if it is a more specific type.
Generally occurs in languages with a single inheritance tree,
where the only type we may have associated with a value is the
class “Object”.
Solving this problem generally requires values to have “self
knowledge” of their own type. In some languages they do, in some
languages values do not.
Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 12 / 20
Static and Dynamic Typing
STATIC AND DYNAMIC METHOD BINDING
Should the binding for information be associated with the static
class of a variable or the dynamic class. Alice holds a small
Mammal - asks Bill “does this animal give birth to live young”.
Static answer – All mammals give birth to live young – therefore
yes.
What if the Mammal is a platypus? Dynamic answer – Platypus
lay eggs, therefore no.
Even statically typed OOP languages can use dynamic binding.
But may use static type to determine legality of operation.
Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 13 / 20
Static and Dynamic Typing
DOCUMENTING METHOD BINDING I
In many languages dynamic binding is the default.
If a child class overrides a method in the parent, using the same
type signature, then the selected method will be determined by
the dynamic type.
In other languages (C++, Delphi, C#) the programmer must
indicate which methods are dynamically bound and which are
statically type.
In C#, for example, this is done using the virtual keyword.
Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 14 / 20
Static and Dynamic Typing
DOCUMENTING METHOD BINDING II
METHOD BINDING
class Animal { Animal a ;
public : Dog b ;
virtual void speak ( ) { cout << " Animal Speak !  n" ; } b . speak ( ) ;
void reply ( ) { cout << " Animal Reply !  n" ; } woof !
} ;
class Dog : Animal { a = b ;
public : a . speak ( ) ;
override void speak ( ) { cout << " woof !  n" ; } woof !
void reply ( ) { cout << " woof again !  n" ; }
} ; Bird c ;
c . speak ( ) ;
class Bird : Animal { tweet !
public : a = c ;
virtual void speak ( ) { cout << " tweet !  n" ; } a . speak ( ) ;
} ; tweet !
Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 15 / 20
Static and Dynamic Typing
METHOD BINDING IN C++ I
C++ is the most complex language. Not only must the
programmer use the virtual keyword, but true polymorphism only
occurs with pointer or reference variables.
We will see an explanation for the curious C++ semantics when
we discuss memory management in the next chapter.
Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 16 / 20
Static and Dynamic Typing
METHOD BINDING IN C++ II
METHOD BINDING IN C++
class Animal { Animal ∗ a ;
public : Dog ∗ b =new Dog ( ) ;
virtual void speak ( ) { cout << " Animal Speak !  n" ; } b−>speak ( ) ;
void reply ( ) { cout << " Animal Reply !  n" ; } woof !
} ;
class Dog : public Animal { a = b ;
public : a−>speak ( ) ;
virtual void speak ( ) { cout << " woof !  n" ; } woof !
void reply ( ) { cout << " woof again !  n" ; } Bird c = new Bird ( ) ;
} ; c−>speak ( ) ;
class Bird : public Animal { tweet !
public : a = c ;
virtual void speak ( ) { cout << " tweet !  n" ; } a−>speak ( ) ;
} ; tweet !
Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 17 / 20
Static and Dynamic Typing
MERITS OF STATIC VS DYNAMIC BINDING
Arguments concerning static versus dynamic binding mirror those
concerning static versus dynamic typing.
Efficiency – static binding uses least CPU cycles, dynamic binding
requires more time.
Error detection – static binding permits errors to be caught at
compile time rather than run-time.
Flexibility – dynamic binding permits greater flexibility, static
binding creates rigidity and inhibits reuse.
Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 18 / 20
Static and Dynamic Typing
SUMMARY
A statically typed language associated types with variables, a
dynamically typed language associates types with values.
Static typing gives better error detection, better run-time efficiency,
less flexibility.
In a statically typed OO language, an object variable can still hold
values from a child class.
The static class is the class of the declaration, the dynamic class
is the class of the value currently held.
The legality of a message is checked using the static class.
A message can be bound to a method using either the static or
dynamic class. Most languages use the dynamic class.
Some languages allow the programmer to choose which method
is used.
Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 19 / 20
References
REFERENCES I
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:
CambridgeUS, dove.
Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 20 / 20

More Related Content

What's hot

Assembly Language Lecture 5
Assembly Language Lecture 5Assembly Language Lecture 5
Assembly Language Lecture 5Motaz Saad
 
Theory of Automata
Theory of AutomataTheory of Automata
Theory of AutomataFarooq Mian
 
8 statement-level control structure
8 statement-level control structure8 statement-level control structure
8 statement-level control structurejigeno
 
1.7. eqivalence of nfa and dfa
1.7. eqivalence of nfa and dfa1.7. eqivalence of nfa and dfa
1.7. eqivalence of nfa and dfaSampath Kumar S
 
Closure properties of context free grammar
Closure properties of context free grammarClosure properties of context free grammar
Closure properties of context free grammarAfshanKhan51
 
flowchart & algorithms
flowchart & algorithmsflowchart & algorithms
flowchart & algorithmsStudent
 
Code generation errors and recovery
Code generation errors and recoveryCode generation errors and recovery
Code generation errors and recoveryMomina Idrees
 
Software Quality Assurance (May – 2019) [Choice Based | Question Paper]
Software Quality Assurance (May – 2019) [Choice Based | Question Paper]Software Quality Assurance (May – 2019) [Choice Based | Question Paper]
Software Quality Assurance (May – 2019) [Choice Based | Question Paper]Mumbai B.Sc.IT Study
 
Finite automata(For college Seminars)
Finite automata(For college Seminars)Finite automata(For college Seminars)
Finite automata(For college Seminars)Naman Joshi
 
Basic Blocks and Flow Graphs
Basic Blocks and Flow GraphsBasic Blocks and Flow Graphs
Basic Blocks and Flow GraphsJenny Galino
 

What's hot (14)

Assembly Language Lecture 5
Assembly Language Lecture 5Assembly Language Lecture 5
Assembly Language Lecture 5
 
Theory of Automata
Theory of AutomataTheory of Automata
Theory of Automata
 
Storage class
Storage classStorage class
Storage class
 
8 statement-level control structure
8 statement-level control structure8 statement-level control structure
8 statement-level control structure
 
1.7. eqivalence of nfa and dfa
1.7. eqivalence of nfa and dfa1.7. eqivalence of nfa and dfa
1.7. eqivalence of nfa and dfa
 
Closure properties of context free grammar
Closure properties of context free grammarClosure properties of context free grammar
Closure properties of context free grammar
 
flowchart & algorithms
flowchart & algorithmsflowchart & algorithms
flowchart & algorithms
 
Code generation errors and recovery
Code generation errors and recoveryCode generation errors and recovery
Code generation errors and recovery
 
File Handling In C++
File Handling In C++File Handling In C++
File Handling In C++
 
Software Quality Assurance (May – 2019) [Choice Based | Question Paper]
Software Quality Assurance (May – 2019) [Choice Based | Question Paper]Software Quality Assurance (May – 2019) [Choice Based | Question Paper]
Software Quality Assurance (May – 2019) [Choice Based | Question Paper]
 
Finite automata(For college Seminars)
Finite automata(For college Seminars)Finite automata(For college Seminars)
Finite automata(For college Seminars)
 
Theory of computation and automata
Theory of computation and automataTheory of computation and automata
Theory of computation and automata
 
Basic Blocks and Flow Graphs
Basic Blocks and Flow GraphsBasic Blocks and Flow Graphs
Basic Blocks and Flow Graphs
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 

Similar to Static and Dynamic Behavior

Subclasses and Subtypes
Subclasses and SubtypesSubclasses and Subtypes
Subclasses and Subtypesadil raja
 
Implications of Substitution
Implications of SubstitutionImplications of Substitution
Implications of Substitutionadil raja
 
Messages, Instances and Initialization
Messages, Instances and InitializationMessages, Instances and Initialization
Messages, Instances and Initializationadil raja
 
Grooming with Groovy
Grooming with GroovyGrooming with Groovy
Grooming with GroovyDhaval Dalal
 
Maintenance of Dynamically vs. Statically typed Languages
Maintenance of Dynamically vs. Statically typed LanguagesMaintenance of Dynamically vs. Statically typed Languages
Maintenance of Dynamically vs. Statically typed LanguagesAmin Bandeali
 
State of NLP and Amazon Comprehend
State of NLP and Amazon ComprehendState of NLP and Amazon Comprehend
State of NLP and Amazon ComprehendEgor Pushkin
 
DTS s03e04 Typing
DTS s03e04 TypingDTS s03e04 Typing
DTS s03e04 TypingTuenti
 
Julia + R for Data Science
Julia + R for Data ScienceJulia + R for Data Science
Julia + R for Data ScienceWork-Bench
 
Language-Based Information-Flow Security
Language-Based Information-Flow SecurityLanguage-Based Information-Flow Security
Language-Based Information-Flow SecurityAkram El-Korashy
 
CommunityOneEast 09 - Dynamic Languages: the next big thing for the JVM or an...
CommunityOneEast 09 - Dynamic Languages: the next big thing for the JVM or an...CommunityOneEast 09 - Dynamic Languages: the next big thing for the JVM or an...
CommunityOneEast 09 - Dynamic Languages: the next big thing for the JVM or an...Chris Richardson
 
invokedynamic: Evolution of a Language Feature
invokedynamic: Evolution of a Language Featureinvokedynamic: Evolution of a Language Feature
invokedynamic: Evolution of a Language FeatureDanHeidinga
 
Does Java Have a Future After Version 8? (Belfast JUG April 2014)
Does Java Have a Future After Version 8? (Belfast JUG April 2014)Does Java Have a Future After Version 8? (Belfast JUG April 2014)
Does Java Have a Future After Version 8? (Belfast JUG April 2014)Garth Gilmour
 

Similar to Static and Dynamic Behavior (12)

Subclasses and Subtypes
Subclasses and SubtypesSubclasses and Subtypes
Subclasses and Subtypes
 
Implications of Substitution
Implications of SubstitutionImplications of Substitution
Implications of Substitution
 
Messages, Instances and Initialization
Messages, Instances and InitializationMessages, Instances and Initialization
Messages, Instances and Initialization
 
Grooming with Groovy
Grooming with GroovyGrooming with Groovy
Grooming with Groovy
 
Maintenance of Dynamically vs. Statically typed Languages
Maintenance of Dynamically vs. Statically typed LanguagesMaintenance of Dynamically vs. Statically typed Languages
Maintenance of Dynamically vs. Statically typed Languages
 
State of NLP and Amazon Comprehend
State of NLP and Amazon ComprehendState of NLP and Amazon Comprehend
State of NLP and Amazon Comprehend
 
DTS s03e04 Typing
DTS s03e04 TypingDTS s03e04 Typing
DTS s03e04 Typing
 
Julia + R for Data Science
Julia + R for Data ScienceJulia + R for Data Science
Julia + R for Data Science
 
Language-Based Information-Flow Security
Language-Based Information-Flow SecurityLanguage-Based Information-Flow Security
Language-Based Information-Flow Security
 
CommunityOneEast 09 - Dynamic Languages: the next big thing for the JVM or an...
CommunityOneEast 09 - Dynamic Languages: the next big thing for the JVM or an...CommunityOneEast 09 - Dynamic Languages: the next big thing for the JVM or an...
CommunityOneEast 09 - Dynamic Languages: the next big thing for the JVM or an...
 
invokedynamic: Evolution of a Language Feature
invokedynamic: Evolution of a Language Featureinvokedynamic: Evolution of a Language Feature
invokedynamic: Evolution of a Language Feature
 
Does Java Have a Future After Version 8? (Belfast JUG April 2014)
Does Java Have a Future After Version 8? (Belfast JUG April 2014)Does Java Have a Future After Version 8? (Belfast JUG April 2014)
Does Java Have a Future After Version 8? (Belfast JUG April 2014)
 

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

(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
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
 
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
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
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
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 

Recently uploaded (20)

(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
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...
 
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
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
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
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 

Static and Dynamic Behavior

  • 1. STATIC AND DYNAMIC BEHAVIOR Muhammad Adil Raja Roaming Researchers, Inc. cbna April 19, 2015 Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 1 / 20
  • 2. OUTLINE I 1 INTRODUCTION 2 STATIC AND DYNAMIC TYPING 3 REFERENCES Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 2 / 20
  • 3. Introduction INTRODUCTION How differences in static and dynamic features effect object-oriented programming languages. Static versus Dynamic Typing. Static and Dynamic Classes in Statically Typed Languages. Static and Dynamic Method Binding in Statically Typed Languages. Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 3 / 20
  • 4. Static and Dynamic Typing WHAT DO THE TERMS STATIC AND DYNAMIC MEAN? MESSAGE SYNTAX In Programming languages: Static almost always means fixed or bound at compile time, and cannot thereafter be changed. Dynamic almost always means not fixed or bound until run time, and therefore can change during the course of execution. Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 4 / 20
  • 5. Static and Dynamic Typing STATIC AND DYNAMIC TYPING In a statically typed programming language (Java or Pascal), for example, variables have declared types – fixed at compile time. In a dynamically typed programming language (Smalltalk or CLOS), a variable is just a name. Types are associated with values, not variables. A variable can hold different types during the course of execution. Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 5 / 20
  • 6. Static and Dynamic Typing ARGUMENTS FOR THE AGAINST Static and Dynamically typed languages have existed as long as there have been programming languages. Arguments for and against: Static typing allows better error detection, more work at compile time and hence faster execution time. Dynamic typing allows greater flexibility, easier to write (for example, no declaration statements). Both arguments have some validity, and hence both types of languages will continue to exist in the future. Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 6 / 20
  • 7. Static and Dynamic Typing THE POLYMORPHIC VARIABLE The addition of object-oriented ideas in a statically typed languages adds a new twist. Recall the argument for substitution: an instance of a child class should be allowed to be assigned to a variable of the parent class: THE POLYMORPHIC VARIABLE var pet : Mammal; f i d o : Dog ; f e l i c e : Cat ; begin pet := f i d o ; / / legal pet := f e l i c e ; / / legal f i d o := pet ; / / not legal ! Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 7 / 20
  • 8. Static and Dynamic Typing STATIC CLASS AND DYNAMIC CLASS In a statically typed language we say the class of the declaration is the static class for the variable, while the class of the value it currently holds is the dynamic class. Most statically typed OO languages constrain the dynamic class to be a child class of the static class. STATIC VS DYNAMIC var pet : Mammal; f i d o : Dog begin pet := f i d o ; / / s t a t i c class i s Mammal, dynamic class i s Dog end ; Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 8 / 20
  • 9. Static and Dynamic Typing IMPORTANCE OF STATIC CLASS In a statically typed object-oriented language, the legality of a message is determined at compile time, based on the static class. A message can produce a compile error, even if no run-time error could possibly arize: class Mammal { } class Dog extends Mammal { void speak ( ) { System . out . p r i n t l n ( " woof " ) ; } } Mammal pet = new Dog ; pet . speak ( ) ; / / w i l l generate error , Mammals don ’ t speak Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 9 / 20
  • 10. Static and Dynamic Typing REVERSE POLYMORPHISM Polymorphism says we can assign a value from a child class to an instance of the parent class, but can this assignment then be reversed? Under what conditions? This is known as the problem of reverse polymorphism. REVERSE POLYMORPHISM var pet : Mammal; f i d o : Dog ; f e l i c e : Cat ; begin pet := f i d o ; / / legal f i d o := pet ; / / i s t h i s legal ? end ; Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 10 / 20
  • 11. Static and Dynamic Typing TWO ASPECTS OF REVERSE POLYMORPHISM There are two specific problems associated with the question of reverse polymorphism. The problem of identity – can I tell if a value declared as an instance of a parent class actually holds a value from a subclass. The task of assignment – can I then assign the value from the parent class to a variable declared as the subclass. In some languages mechanisms are provided to address these two problems together, while in other languages they are separated. Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 11 / 20
  • 12. Static and Dynamic Typing THE CONTAINER PROBLEM The task of reverse polymorphism is often encountered in connection with a collection of values - we have a list of items from the parent class (say a list of Mammals), and when we extract a value we need to know if it is a more specific type. Generally occurs in languages with a single inheritance tree, where the only type we may have associated with a value is the class “Object”. Solving this problem generally requires values to have “self knowledge” of their own type. In some languages they do, in some languages values do not. Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 12 / 20
  • 13. Static and Dynamic Typing STATIC AND DYNAMIC METHOD BINDING Should the binding for information be associated with the static class of a variable or the dynamic class. Alice holds a small Mammal - asks Bill “does this animal give birth to live young”. Static answer – All mammals give birth to live young – therefore yes. What if the Mammal is a platypus? Dynamic answer – Platypus lay eggs, therefore no. Even statically typed OOP languages can use dynamic binding. But may use static type to determine legality of operation. Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 13 / 20
  • 14. Static and Dynamic Typing DOCUMENTING METHOD BINDING I In many languages dynamic binding is the default. If a child class overrides a method in the parent, using the same type signature, then the selected method will be determined by the dynamic type. In other languages (C++, Delphi, C#) the programmer must indicate which methods are dynamically bound and which are statically type. In C#, for example, this is done using the virtual keyword. Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 14 / 20
  • 15. Static and Dynamic Typing DOCUMENTING METHOD BINDING II METHOD BINDING class Animal { Animal a ; public : Dog b ; virtual void speak ( ) { cout << " Animal Speak ! n" ; } b . speak ( ) ; void reply ( ) { cout << " Animal Reply ! n" ; } woof ! } ; class Dog : Animal { a = b ; public : a . speak ( ) ; override void speak ( ) { cout << " woof ! n" ; } woof ! void reply ( ) { cout << " woof again ! n" ; } } ; Bird c ; c . speak ( ) ; class Bird : Animal { tweet ! public : a = c ; virtual void speak ( ) { cout << " tweet ! n" ; } a . speak ( ) ; } ; tweet ! Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 15 / 20
  • 16. Static and Dynamic Typing METHOD BINDING IN C++ I C++ is the most complex language. Not only must the programmer use the virtual keyword, but true polymorphism only occurs with pointer or reference variables. We will see an explanation for the curious C++ semantics when we discuss memory management in the next chapter. Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 16 / 20
  • 17. Static and Dynamic Typing METHOD BINDING IN C++ II METHOD BINDING IN C++ class Animal { Animal ∗ a ; public : Dog ∗ b =new Dog ( ) ; virtual void speak ( ) { cout << " Animal Speak ! n" ; } b−>speak ( ) ; void reply ( ) { cout << " Animal Reply ! n" ; } woof ! } ; class Dog : public Animal { a = b ; public : a−>speak ( ) ; virtual void speak ( ) { cout << " woof ! n" ; } woof ! void reply ( ) { cout << " woof again ! n" ; } Bird c = new Bird ( ) ; } ; c−>speak ( ) ; class Bird : public Animal { tweet ! public : a = c ; virtual void speak ( ) { cout << " tweet ! n" ; } a−>speak ( ) ; } ; tweet ! Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 17 / 20
  • 18. Static and Dynamic Typing MERITS OF STATIC VS DYNAMIC BINDING Arguments concerning static versus dynamic binding mirror those concerning static versus dynamic typing. Efficiency – static binding uses least CPU cycles, dynamic binding requires more time. Error detection – static binding permits errors to be caught at compile time rather than run-time. Flexibility – dynamic binding permits greater flexibility, static binding creates rigidity and inhibits reuse. Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 18 / 20
  • 19. Static and Dynamic Typing SUMMARY A statically typed language associated types with variables, a dynamically typed language associates types with values. Static typing gives better error detection, better run-time efficiency, less flexibility. In a statically typed OO language, an object variable can still hold values from a child class. The static class is the class of the declaration, the dynamic class is the class of the value currently held. The legality of a message is checked using the static class. A message can be bound to a method using either the static or dynamic class. Most languages use the dynamic class. Some languages allow the programmer to choose which method is used. Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 19 / 20
  • 20. References REFERENCES I 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: CambridgeUS, dove. Muhammad Adil Raja ( Roaming Researchers, Inc. cbna)Static and Dynamic Behavior April 19, 2015 20 / 20