SlideShare a Scribd company logo
Introduction Template Functions Template Classes Bounded Genericity Summary References
GENERICS
Muhammad Adil Raja
Roaming Researchers, Inc.
cbna
April 21, 2015
Generics Roaming Researchers, Inc. cbna
Introduction Template Functions Template Classes Bounded Genericity Summary References
OUTLINE I
INTRODUCTION
TEMPLATE FUNCTIONS
TEMPLATE CLASSES
BOUNDED GENERICITY
SUMMARY
REFERENCES
Generics Roaming Researchers, Inc. cbna
Introduction Template Functions Template Classes Bounded Genericity Summary References
INTRODUCTION
The idea of a generic (or template) is yet another approach
to software reuse.
The basic idea is to develop code by leave certain key
types unspecified, to be filled in later.
In many ways this is like a parameter that is filled with may
different values.
Here, however, the parameters are types, and not values.
Generics are used both with functions and with classes.
Generics Roaming Researchers, Inc. cbna
Introduction Template Functions Template Classes Bounded Genericity Summary References
TEMPLATE FUNCTIONS
The following illustrates a simple template function in C++,
and its use.
TEMPLATE FUNCTION
template <class T> T max(T l e f t , T r i g h t ) {
i f ( l e f t < r i g h t )
return r i g h t ;
return l e f t ;
}
int a = max(3 , 27);
double d = max(3.14 , 2.75); / / see how types d i f f e r
Generics Roaming Researchers, Inc. cbna
Introduction Template Functions Template Classes Bounded Genericity Summary References
CAN EVEN BE USED WITH USER-DEFINED TYPES
EXAMPLE
class Fraction {
public :
Fraction ( int top , int bottom ) { t = top ; b = bottom ; }
int numerator ( ) { return t ; }
int denominator ( ) { return b ; }
bool operator < ( Fraction & r i g h t )
{ return t ∗ r i g h t . b < r i g h t . t ∗ b ; }
private :
int t , b ;
} ;
Fraction x (3 , 4 ) ;
Fraction y (7 , 8 ) ;
Fraction z = max( x , y ) ;
Generics Roaming Researchers, Inc. cbna
Introduction Template Functions Template Classes Bounded Genericity Summary References
TEMPLATE CLASSES
While template functions are useful, it is more common to
use templates with classes.
TEMPLATE CLASSES
template <class T> class Box {
public :
Box (T i n i t i a l ) : value ( i n i t i a l ) { }
T getValue ( ) { return value ; }
setValue (T newValue ) { value = newValue ; }
private :
T value ;
} ;
Box<int > iBox ( 7 ) ;
cout << iBox . getValue ( ) ;
7
iBox . setValue ( 1 2 ) ;
cout << iBox . getValue ( ) ;
12
Notice how the programmer filled in the template argument
when creating a new variable.Generics Roaming Researchers, Inc. cbna
Introduction Template Functions Template Classes Bounded Genericity Summary References
CAN BE FILLED WITH DIFFERENT ARGUMENTS
EXAMPLE
iBox . setValue (3.1415); / / ERROR − i n v a l i d type
Box <double> dBox ( 2 . 7 ) ;
cout << dBox . getValue ( ) ;
2.7
dBox . setValue (3.1415);
cout << dBox . getValue ( ) ;
3.1415
iBox = dBox ; / / ERROR − mismatched types
In the next chapter we will see how generics are used to create
collection classes.
Generics Roaming Researchers, Inc. cbna
Introduction Template Functions Template Classes Bounded Genericity Summary References
BOUNDED GENERICITY
Some languages (Eiffel, others) allow the programmer to place
a type on the template argument:
GENERICITY
class
Hash_Table [ H −> Hashable ]
. . .
The restriction says that the argument (here named H) can
only be a subclass of Hashable.
This feature allows the compiler to do stronger type
checking, and produce more meaningful error messages.
Generics Roaming Researchers, Inc. cbna
Introduction Template Functions Template Classes Bounded Genericity Summary References
INHERITANCE AND GENERICS
Remember the class Box.
Suppose a class Person has subclasses BoyChild and
GirlChild.
What is the relationship between Box[Person] and
Box[BoyChild]?
Unfortunately, runs into problems with the principle of
substitution.
Assume Box[BoyChild] is a subclass of Box[Person], would
make the following legal:
EXAMPLE
Box [ Person ] aBox = new Box [ BoyChild ] ;
Person aGirl = new G i r l C h i l d ;
aBox . set ( aGirl ) ;
A similar argument can be made for the reverse.Generics Roaming Researchers, Inc. cbna
Introduction Template Functions Template Classes Bounded Genericity Summary References
INHERITANCE AND ARRAYS
Can make a similar argument for arrays:
EXAMPLE
BoyChild [ ] boys = new BoyChild [ 1 0 ] ;
Person [ ] people = boys ; / / copy or pointer semantics?
G i r l C h i l d s a l l y = new G i r l C h i l d ;
people [ 1 ] = s a l l y ;
If pointer semantics are used for the array assignment then
this can produce type errors.
Java allows the assignment, but uses a run-time check to
catch the last assignment error!
Other languages make the array assignment illegal.
Generics Roaming Researchers, Inc. cbna
Introduction Template Functions Template Classes Bounded Genericity 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.
Generics Roaming Researchers, Inc. cbna
Introduction Template Functions Template Classes Bounded Genericity 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, monarca.
Generics Roaming Researchers, Inc. cbna

More Related Content

What's hot

Polymorphism in C++
Polymorphism in C++Polymorphism in C++
Polymorphism in C++
Rabin BK
 
Interfaces
InterfacesInterfaces
Interfaces
Jai Marathe
 
C++ Object Oriented Programming
C++  Object Oriented ProgrammingC++  Object Oriented Programming
C++ Object Oriented Programming
Gamindu Udayanga
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
Sanjit Shaw
 
Polymorphism in oop
Polymorphism in oopPolymorphism in oop
Polymorphism in oop
MustafaIbrahimy
 
OOPS IN C++
OOPS IN C++OOPS IN C++
OOPS IN C++
Amritsinghmehra
 
Javapolymorphism
JavapolymorphismJavapolymorphism
Javapolymorphism
karthikenlume
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
Selvin Josy Bai Somu
 
Lecture 9 access modifiers and packages
Lecture   9 access modifiers and packagesLecture   9 access modifiers and packages
Lecture 9 access modifiers and packages
manish kumar
 
Java(Polymorphism)
Java(Polymorphism)Java(Polymorphism)
Java(Polymorphism)
harsh kothari
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
sureshraj43
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in java
Ahsan Raja
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
Kumar Gaurav
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
Elizabeth alexander
 
Lecture 8 abstract class and interface
Lecture   8 abstract class and interfaceLecture   8 abstract class and interface
Lecture 8 abstract class and interface
manish kumar
 
Abstract class
Abstract classAbstract class
Abstract class
Hoang Nguyen
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
Mufaddal Nullwala
 
3.5
3.53.5
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
CPD INDIA
 
Polymorphism in Java
Polymorphism in JavaPolymorphism in Java
Polymorphism in Java
Java2Blog
 

What's hot (20)

Polymorphism in C++
Polymorphism in C++Polymorphism in C++
Polymorphism in C++
 
Interfaces
InterfacesInterfaces
Interfaces
 
C++ Object Oriented Programming
C++  Object Oriented ProgrammingC++  Object Oriented Programming
C++ Object Oriented Programming
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
 
Polymorphism in oop
Polymorphism in oopPolymorphism in oop
Polymorphism in oop
 
OOPS IN C++
OOPS IN C++OOPS IN C++
OOPS IN C++
 
Javapolymorphism
JavapolymorphismJavapolymorphism
Javapolymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Lecture 9 access modifiers and packages
Lecture   9 access modifiers and packagesLecture   9 access modifiers and packages
Lecture 9 access modifiers and packages
 
Java(Polymorphism)
Java(Polymorphism)Java(Polymorphism)
Java(Polymorphism)
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in java
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
 
Lecture 8 abstract class and interface
Lecture   8 abstract class and interfaceLecture   8 abstract class and interface
Lecture 8 abstract class and interface
 
Abstract class
Abstract classAbstract class
Abstract class
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
 
3.5
3.53.5
3.5
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Polymorphism in Java
Polymorphism in JavaPolymorphism in Java
Polymorphism in Java
 

Viewers also liked

The Polymorphic Variable
The Polymorphic VariableThe Polymorphic Variable
The Polymorphic Variable
adil raja
 
Implications of Substitution
Implications of SubstitutionImplications of Substitution
Implications of Substitution
adil raja
 
Object Interconnections
Object InterconnectionsObject Interconnections
Object Interconnections
adil raja
 
Overriding
OverridingOverriding
Overriding
adil raja
 
Messages, Instances and Initialization
Messages, Instances and InitializationMessages, Instances and Initialization
Messages, Instances and Initialization
adil raja
 
Overloading
OverloadingOverloading
Overloading
adil raja
 
Implementation
ImplementationImplementation
Implementation
adil raja
 
The STL
The STLThe STL
The STL
adil raja
 
Distributed Computing
Distributed ComputingDistributed Computing
Distributed Computing
adil raja
 
Container Classes
Container ClassesContainer Classes
Container Classes
adil raja
 
Polymorphism and Software Reuse
Polymorphism and Software ReusePolymorphism and Software Reuse
Polymorphism and Software Reuse
adil raja
 
Object-Oriented Design
Object-Oriented DesignObject-Oriented Design
Object-Oriented Design
adil raja
 
Classes And Methods
Classes And MethodsClasses And Methods
Classes And Methods
adil raja
 
Thinking Object-Oriented
Thinking Object-OrientedThinking Object-Oriented
Thinking Object-Oriented
adil raja
 
Static and Dynamic Behavior
Static and Dynamic BehaviorStatic and Dynamic Behavior
Static and Dynamic Behavior
adil raja
 
Inheritance and Substitution
Inheritance and SubstitutionInheritance and Substitution
Inheritance and Substitution
adil raja
 
Subclasses and Subtypes
Subclasses and SubtypesSubclasses and Subtypes
Subclasses and Subtypes
adil raja
 
Reflection and Introspection
Reflection and IntrospectionReflection and Introspection
Reflection and Introspection
adil raja
 
The AWT and Swing
The AWT and SwingThe AWT and Swing
The AWT and Swing
adil raja
 
Software Frameworks
Software FrameworksSoftware Frameworks
Software Frameworks
adil raja
 

Viewers also liked (20)

The Polymorphic Variable
The Polymorphic VariableThe Polymorphic Variable
The Polymorphic Variable
 
Implications of Substitution
Implications of SubstitutionImplications of Substitution
Implications of Substitution
 
Object Interconnections
Object InterconnectionsObject Interconnections
Object Interconnections
 
Overriding
OverridingOverriding
Overriding
 
Messages, Instances and Initialization
Messages, Instances and InitializationMessages, Instances and Initialization
Messages, Instances and Initialization
 
Overloading
OverloadingOverloading
Overloading
 
Implementation
ImplementationImplementation
Implementation
 
The STL
The STLThe STL
The STL
 
Distributed Computing
Distributed ComputingDistributed Computing
Distributed Computing
 
Container Classes
Container ClassesContainer Classes
Container Classes
 
Polymorphism and Software Reuse
Polymorphism and Software ReusePolymorphism and Software Reuse
Polymorphism and Software Reuse
 
Object-Oriented Design
Object-Oriented DesignObject-Oriented Design
Object-Oriented Design
 
Classes And Methods
Classes And MethodsClasses And Methods
Classes And Methods
 
Thinking Object-Oriented
Thinking Object-OrientedThinking Object-Oriented
Thinking Object-Oriented
 
Static and Dynamic Behavior
Static and Dynamic BehaviorStatic and Dynamic Behavior
Static and Dynamic Behavior
 
Inheritance and Substitution
Inheritance and SubstitutionInheritance and Substitution
Inheritance and Substitution
 
Subclasses and Subtypes
Subclasses and SubtypesSubclasses and Subtypes
Subclasses and Subtypes
 
Reflection and Introspection
Reflection and IntrospectionReflection and Introspection
Reflection and Introspection
 
The AWT and Swing
The AWT and SwingThe AWT and Swing
The AWT and Swing
 
Software Frameworks
Software FrameworksSoftware Frameworks
Software Frameworks
 

Similar to Generics

C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01
Zafor Iqbal
 
Introduction to new features in java 8
Introduction to new features in java 8Introduction to new features in java 8
Introduction to new features in java 8
Introduction to new features in java 8Introduction to new features in java 8
Introduction to new features in java 8
Raffi Khatchadourian
 
java vs C#
java vs C#java vs C#
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptxINDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
Indu65
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
1HK19CS090MOHAMMEDSA
 
Seminar
SeminarSeminar
SEMINAR
SEMINARSEMINAR
Difference between Java and c#
Difference between Java and c#Difference between Java and c#
Difference between Java and c#
Sagar Pednekar
 
Notes(1).pptx
Notes(1).pptxNotes(1).pptx
Notes(1).pptx
InfinityWorld3
 
Swift, swiftly
Swift, swiftlySwift, swiftly
Swift, swiftly
Jack Nutting
 
Future Programming Language
Future Programming LanguageFuture Programming Language
Future Programming Language
YLTO
 
Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
shubhra chauhan
 
Generics
GenericsGenerics
Csci360 20
Csci360 20Csci360 20
Csci360 20
neetukalra
 
Csci360 20 (1)
Csci360 20 (1)Csci360 20 (1)
Csci360 20 (1)
manish katara
 
Md03 - part3
Md03 - part3Md03 - part3
Md03 - part3
Rakesh Madugula
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
Pranali Chaudhari
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
Martin Odersky
 
Ppt of c vs c#
Ppt of c vs c#Ppt of c vs c#
Ppt of c vs c#
shubhra chauhan
 

Similar to Generics (20)

C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01
 
Introduction to new features in java 8
Introduction to new features in java 8Introduction to new features in java 8
Introduction to new features in java 8
 
Introduction to new features in java 8
Introduction to new features in java 8Introduction to new features in java 8
Introduction to new features in java 8
 
java vs C#
java vs C#java vs C#
java vs C#
 
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptxINDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
 
Seminar
SeminarSeminar
Seminar
 
SEMINAR
SEMINARSEMINAR
SEMINAR
 
Difference between Java and c#
Difference between Java and c#Difference between Java and c#
Difference between Java and c#
 
Notes(1).pptx
Notes(1).pptxNotes(1).pptx
Notes(1).pptx
 
Swift, swiftly
Swift, swiftlySwift, swiftly
Swift, swiftly
 
Future Programming Language
Future Programming LanguageFuture Programming Language
Future Programming Language
 
Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
 
Generics
GenericsGenerics
Generics
 
Csci360 20
Csci360 20Csci360 20
Csci360 20
 
Csci360 20 (1)
Csci360 20 (1)Csci360 20 (1)
Csci360 20 (1)
 
Md03 - part3
Md03 - part3Md03 - part3
Md03 - part3
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Ppt of c vs c#
Ppt of c vs c#Ppt of c vs c#
Ppt of c vs c#
 

More from adil raja

ANNs.pdf
ANNs.pdfANNs.pdf
ANNs.pdf
adil raja
 
A Software Requirements Specification
A Software Requirements SpecificationA Software Requirements Specification
A Software Requirements Specification
adil 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 Vehicles
adil raja
 
DevOps Demystified
DevOps DemystifiedDevOps Demystified
DevOps Demystified
adil 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 Research
adil raja
 
The Knock Knock Protocol
The Knock Knock ProtocolThe Knock Knock Protocol
The Knock Knock Protocol
adil raja
 
File Transfer Through Sockets
File Transfer Through SocketsFile Transfer Through Sockets
File Transfer Through Sockets
adil raja
 
Remote Command Execution
Remote Command ExecutionRemote Command Execution
Remote Command Execution
adil raja
 
Thesis
ThesisThesis
Thesis
adil 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 Pakistan
adil raja
 
Data Warehousing
Data WarehousingData Warehousing
Data Warehousing
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
 
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 VoIP
adil raja
 
VoIP
VoIPVoIP
VoIP
adil raja
 
ULMAN GUI Specifications
ULMAN GUI SpecificationsULMAN GUI Specifications
ULMAN GUI Specifications
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
 
ULMAN-GUI
ULMAN-GUIULMAN-GUI
ULMAN-GUI
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

8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
Liberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptxLiberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptx
Massimo Artizzu
 
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
kgyxske
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
The Third Creative Media
 
TMU毕业证书精仿办理
TMU毕业证书精仿办理TMU毕业证书精仿办理
TMU毕业证书精仿办理
aeeva
 
DevOps Consulting Company | Hire DevOps Services
DevOps Consulting Company | Hire DevOps ServicesDevOps Consulting Company | Hire DevOps Services
DevOps Consulting Company | Hire DevOps Services
seospiralmantra
 
ppt on the brain chip neuralink.pptx
ppt  on   the brain  chip neuralink.pptxppt  on   the brain  chip neuralink.pptx
ppt on the brain chip neuralink.pptx
Reetu63
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
kalichargn70th171
 
The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024
Yara Milbes
 
What’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete RoadmapWhat’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete Roadmap
Envertis Software Solutions
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
kalichargn70th171
 
Superpower Your Apache Kafka Applications Development with Complementary Open...
Superpower Your Apache Kafka Applications Development with Complementary Open...Superpower Your Apache Kafka Applications Development with Complementary Open...
Superpower Your Apache Kafka Applications Development with Complementary Open...
Paul Brebner
 
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Paul Brebner
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
sjcobrien
 
ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.
Maitrey Patel
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
dakas1
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
Alberto Brandolini
 

Recently uploaded (20)

8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
Liberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptxLiberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptx
 
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
 
TMU毕业证书精仿办理
TMU毕业证书精仿办理TMU毕业证书精仿办理
TMU毕业证书精仿办理
 
DevOps Consulting Company | Hire DevOps Services
DevOps Consulting Company | Hire DevOps ServicesDevOps Consulting Company | Hire DevOps Services
DevOps Consulting Company | Hire DevOps Services
 
ppt on the brain chip neuralink.pptx
ppt  on   the brain  chip neuralink.pptxppt  on   the brain  chip neuralink.pptx
ppt on the brain chip neuralink.pptx
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
 
The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024
 
What’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete RoadmapWhat’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete Roadmap
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
 
Superpower Your Apache Kafka Applications Development with Complementary Open...
Superpower Your Apache Kafka Applications Development with Complementary Open...Superpower Your Apache Kafka Applications Development with Complementary Open...
Superpower Your Apache Kafka Applications Development with Complementary Open...
 
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
 
ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
 

Generics

  • 1. Introduction Template Functions Template Classes Bounded Genericity Summary References GENERICS Muhammad Adil Raja Roaming Researchers, Inc. cbna April 21, 2015 Generics Roaming Researchers, Inc. cbna
  • 2. Introduction Template Functions Template Classes Bounded Genericity Summary References OUTLINE I INTRODUCTION TEMPLATE FUNCTIONS TEMPLATE CLASSES BOUNDED GENERICITY SUMMARY REFERENCES Generics Roaming Researchers, Inc. cbna
  • 3. Introduction Template Functions Template Classes Bounded Genericity Summary References INTRODUCTION The idea of a generic (or template) is yet another approach to software reuse. The basic idea is to develop code by leave certain key types unspecified, to be filled in later. In many ways this is like a parameter that is filled with may different values. Here, however, the parameters are types, and not values. Generics are used both with functions and with classes. Generics Roaming Researchers, Inc. cbna
  • 4. Introduction Template Functions Template Classes Bounded Genericity Summary References TEMPLATE FUNCTIONS The following illustrates a simple template function in C++, and its use. TEMPLATE FUNCTION template <class T> T max(T l e f t , T r i g h t ) { i f ( l e f t < r i g h t ) return r i g h t ; return l e f t ; } int a = max(3 , 27); double d = max(3.14 , 2.75); / / see how types d i f f e r Generics Roaming Researchers, Inc. cbna
  • 5. Introduction Template Functions Template Classes Bounded Genericity Summary References CAN EVEN BE USED WITH USER-DEFINED TYPES EXAMPLE class Fraction { public : Fraction ( int top , int bottom ) { t = top ; b = bottom ; } int numerator ( ) { return t ; } int denominator ( ) { return b ; } bool operator < ( Fraction & r i g h t ) { return t ∗ r i g h t . b < r i g h t . t ∗ b ; } private : int t , b ; } ; Fraction x (3 , 4 ) ; Fraction y (7 , 8 ) ; Fraction z = max( x , y ) ; Generics Roaming Researchers, Inc. cbna
  • 6. Introduction Template Functions Template Classes Bounded Genericity Summary References TEMPLATE CLASSES While template functions are useful, it is more common to use templates with classes. TEMPLATE CLASSES template <class T> class Box { public : Box (T i n i t i a l ) : value ( i n i t i a l ) { } T getValue ( ) { return value ; } setValue (T newValue ) { value = newValue ; } private : T value ; } ; Box<int > iBox ( 7 ) ; cout << iBox . getValue ( ) ; 7 iBox . setValue ( 1 2 ) ; cout << iBox . getValue ( ) ; 12 Notice how the programmer filled in the template argument when creating a new variable.Generics Roaming Researchers, Inc. cbna
  • 7. Introduction Template Functions Template Classes Bounded Genericity Summary References CAN BE FILLED WITH DIFFERENT ARGUMENTS EXAMPLE iBox . setValue (3.1415); / / ERROR − i n v a l i d type Box <double> dBox ( 2 . 7 ) ; cout << dBox . getValue ( ) ; 2.7 dBox . setValue (3.1415); cout << dBox . getValue ( ) ; 3.1415 iBox = dBox ; / / ERROR − mismatched types In the next chapter we will see how generics are used to create collection classes. Generics Roaming Researchers, Inc. cbna
  • 8. Introduction Template Functions Template Classes Bounded Genericity Summary References BOUNDED GENERICITY Some languages (Eiffel, others) allow the programmer to place a type on the template argument: GENERICITY class Hash_Table [ H −> Hashable ] . . . The restriction says that the argument (here named H) can only be a subclass of Hashable. This feature allows the compiler to do stronger type checking, and produce more meaningful error messages. Generics Roaming Researchers, Inc. cbna
  • 9. Introduction Template Functions Template Classes Bounded Genericity Summary References INHERITANCE AND GENERICS Remember the class Box. Suppose a class Person has subclasses BoyChild and GirlChild. What is the relationship between Box[Person] and Box[BoyChild]? Unfortunately, runs into problems with the principle of substitution. Assume Box[BoyChild] is a subclass of Box[Person], would make the following legal: EXAMPLE Box [ Person ] aBox = new Box [ BoyChild ] ; Person aGirl = new G i r l C h i l d ; aBox . set ( aGirl ) ; A similar argument can be made for the reverse.Generics Roaming Researchers, Inc. cbna
  • 10. Introduction Template Functions Template Classes Bounded Genericity Summary References INHERITANCE AND ARRAYS Can make a similar argument for arrays: EXAMPLE BoyChild [ ] boys = new BoyChild [ 1 0 ] ; Person [ ] people = boys ; / / copy or pointer semantics? G i r l C h i l d s a l l y = new G i r l C h i l d ; people [ 1 ] = s a l l y ; If pointer semantics are used for the array assignment then this can produce type errors. Java allows the assignment, but uses a run-time check to catch the last assignment error! Other languages make the array assignment illegal. Generics Roaming Researchers, Inc. cbna
  • 11. Introduction Template Functions Template Classes Bounded Genericity 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. Generics Roaming Researchers, Inc. cbna
  • 12. Introduction Template Functions Template Classes Bounded Genericity 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, monarca. Generics Roaming Researchers, Inc. cbna