SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Downloaden Sie, um offline zu lesen
Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References
MESSAGES, INSTANCES AND INITIALIZATION
Muhammad Adil Raja
Roaming Researchers, Inc.
cbna
April 15, 2015
Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References
OUTLINE I
1 INTRODUCTION
2 STATIC VS DYNAMIC
3 OBJECT CREATION
4 MEMORY ERRORS
5 CONSTRUCTORS
6 METACLASSES
7 SUMMARY
8 REFERENCES
Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References
INTRODUCTION I
In the previous lesson we studied the static, or compile-time
aspects of classes. In this lesson we shall study their run-time
features.
Message Passing Syntax.
Object Creation and Initialization (constructors).
Accessing the Receiver from within a method.
Memory Management or garbage collection.
Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References
MESSAGES ARE NOT FUNCTION CALLS I
Difference between a message and a function call.
A message is always given to some object, called the
receiver.
The action performed in response is determined by the
receiver, different receivers can do different actions in
response to the same message.
Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References
MESSAGE PASSING SYNTAX I
Although the syntax may differ in different langauges, all
messages have three identifiable parts:
MESSAGE SYNTAX
aGame. displayCard ( aCard , 42 , 27);
The message receiver.
The message selector.
An optional list of arguments.
Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References
STATICALLY TYPED VERSUS DYNAMICALLY TYPED
LANGUAGES I
A statically typed language requires the programmer to
declare a type for each variable.
The validity of a message passing expression will be
checked at compile time, based on the declared type of the
receiver.
A dynamically typed language associates types with
values, not with variables.
A variable is just a name.
The legality of a message cannot be determined until
run-time.
Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References
THE RECEIVER VARIABLE I
Inside a method, the receiver can be accessed by means of a
pseudo-variable.
Called this in Java, C++, C#.
Called self in Smalltalk, Objective-C, Object Pascal.
Called current in Eiffel.
RECEIVER
function PlayingCard . color : colors ;
begin
i f ( s e l f . s u i t = Heart ) or ( s e l f . s u i t = Diamond ) then
color := Red
else
color := Black ;
end
Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References
IMPLICIT USE OF THIS I
Within a method a message expression or a data access with
no explicit receiver is implicitly assumed to refer to this:
RECEIVER
class PlayingCard {
. . .
public void f l i p ( ) { setFaceUp ( ! faceUp ) ; }
. . .
}
Is equivalent to:
class PlayingCard {
. . .
public void f l i p ( ) { this . setFaceUp ( ! this . faceUp ) ; }
. . .
}
Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References
OBJECT CREATION I
In most programming languages objects must be created
dynamically, usually using the new operator:
EXAMPLE OF USAGE OF NEW
PlayingCard aCard ; / / simply names a new variable
aCard = new PlayingCard ( Diamond , 3 ) ; / / creates the new object
The declaration simply names a variable, the new operator is
needed to create the new object value.
Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References
MEMORY RECOVERY I
Because in most languages objects are dynamically allocated,
they must be recovered at run-time. There are two broad
approches to this:
Force the programmer to explicitly say when a value is no
longer being used:
EXAMPLE OF DELETE
delete aCard ; / / C++ example
Use a garbage collection system that will automatically
determine when values are no longer being used, and
recover the memory.
Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References
MEMORY ERRORS I
Garbage collection systems impose a run-time overhead, but
prevent a number of potential memory errors:
Running out of memory because the programmer forgot to
free values
Using a memory value after it has been recovered.
MORE DELETE
PlayingCard ∗ aCard = new PlayingCard (Spade , 1 ) ;
delete aCard ;
cout << aCard . rank ( ) ;
Free the same value twice.
Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References
MEMORY ERRORS II
DELETE CONTINUED
PlayingCard ∗ aCard = new PlayingCard (Spade , 1 ) ;
delete aCard ;
delete aCard ; / / delete already deleted value
Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References
CONSTRUCTORS I
A constructor is a function that is implicitly invoked when a
new object is created.
The constructor performs whatever actions are necessary
in order to initialize the object.
In C++, Java, C# a constructor is a function with the same
name as the class.
In Python constructors are all named – init.
In Delphi, Objective-C, constructors have special syntax,
but can be named anything.
Naming your constructors create is a common convention.
Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References
CONSTRUCTORS II
CONSTRUCTOR
class PlayingCard { / / a Java constructor
public PlayingCard ( int s , int r ) {
s u i t = s ;
rank = r ;
faceUp = true ;
}
. . .
}
Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References
OVERLOADED CONSTRUCTORS I
Constructors are often overloaded, meaning there are a
number of functions with the same name.
They are differentiated by the type signature, and the
arguments used in the function call or declaration:
OVERLOADED CONSTRUCTOR
Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References
OVERLOADED CONSTRUCTORS II
class PlayingCard {
public :
PlayingCard ( ) / / default constructor ,
/ / used when no arguments are given
{ s u i t = Diamond ; rank = 1; faceUp = true ; }
PlayingCard ( Suit i s ) / / constructor with one argument
{ s u i t = i s ; rank = 1; faceUp = true ; }
PlayingCard ( Suit is , int i r ) / / constructor with two arguments
{ s u i t = i s ; rank = i r ; faceUp = true ; }
} ;
Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References
METACLASSES I
In Smalltalk (and Objective-C) classes are just objects,
instances of class Class.
new is just a message given to a class object.
If we want to create constructors, where do we put them?
They can’t be part of the collection of messages of
instances of the class, since we don’t yet have an instance.
They can’t be part of the messages understood by class
Class, since not all classes have the same constructor
message.
Where do we put the behavior for individual class
instances?
Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References
METACLASSES II
The solution is to create a new class, whos only instance is
itself a class. picture
An elegant solution that maintains the simple
instance/class relationship.
Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References
SUMMARY I
In this chapter we have examined the following topics:
Message Passing Syntax.
Object Creation and Initialization (constructors).
Accessing the Receiver from within a method.
Memory Management or garbage collection.
Metaclasses in Smalltalk.
Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References
REFERENCES I
Images and content for developing these slides have been
taken from the follwoing book.
An Introduction to Object Oriented Programming, Timothy
Budd.
This presentation is developed using Beamer:
Berlin, monarca.
Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization

Weitere ähnliche Inhalte

Was ist angesagt?

Object Oriented Programming using JAVA Notes
Object Oriented Programming using JAVA Notes Object Oriented Programming using JAVA Notes
Object Oriented Programming using JAVA Notes Uzair Salman
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript ProgrammingSehwan Noh
 
Design patterns illustrated-2015-03
Design patterns illustrated-2015-03Design patterns illustrated-2015-03
Design patterns illustrated-2015-03Herman Peeren
 
Lambda: A Peek Under The Hood - Brian Goetz
Lambda: A Peek Under The Hood - Brian GoetzLambda: A Peek Under The Hood - Brian Goetz
Lambda: A Peek Under The Hood - Brian GoetzJAX London
 
Sdtl manual
Sdtl manualSdtl manual
Sdtl manualqaz8989
 
Understanding Reflection
Understanding ReflectionUnderstanding Reflection
Understanding ReflectionTamir Khason
 
Extreme Interview Questions
Extreme Interview QuestionsExtreme Interview Questions
Extreme Interview QuestionsEhtisham Ali
 
Top 20 c# interview Question and answers
Top 20 c# interview Question and answersTop 20 c# interview Question and answers
Top 20 c# interview Question and answersw3asp dotnet
 
Core java Basics
Core java BasicsCore java Basics
Core java BasicsRAMU KOLLI
 
2. oop with c++ get 410 day 2
2. oop with c++ get 410   day 22. oop with c++ get 410   day 2
2. oop with c++ get 410 day 2Mukul kumar Neal
 
Java Programming | Java Tutorial For Beginners | Java Training | Edureka
Java Programming | Java Tutorial For Beginners | Java Training | EdurekaJava Programming | Java Tutorial For Beginners | Java Training | Edureka
Java Programming | Java Tutorial For Beginners | Java Training | EdurekaEdureka!
 
Moved to https://slidr.io/azzazzel/osgi-fundamentals
Moved to https://slidr.io/azzazzel/osgi-fundamentalsMoved to https://slidr.io/azzazzel/osgi-fundamentals
Moved to https://slidr.io/azzazzel/osgi-fundamentalsMilen Dyankov
 
50+ java interview questions
50+ java interview questions50+ java interview questions
50+ java interview questionsSynergisticMedia
 
Java session05
Java session05Java session05
Java session05Niit Care
 
Condor overview - glideinWMS Training Jan 2012
Condor overview - glideinWMS Training Jan 2012Condor overview - glideinWMS Training Jan 2012
Condor overview - glideinWMS Training Jan 2012Igor Sfiligoi
 

Was ist angesagt? (20)

Object-oriented Basics
Object-oriented BasicsObject-oriented Basics
Object-oriented Basics
 
Delphi qa
Delphi qaDelphi qa
Delphi qa
 
Object Oriented Programming using JAVA Notes
Object Oriented Programming using JAVA Notes Object Oriented Programming using JAVA Notes
Object Oriented Programming using JAVA Notes
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
Design patterns illustrated-2015-03
Design patterns illustrated-2015-03Design patterns illustrated-2015-03
Design patterns illustrated-2015-03
 
Lambda: A Peek Under The Hood - Brian Goetz
Lambda: A Peek Under The Hood - Brian GoetzLambda: A Peek Under The Hood - Brian Goetz
Lambda: A Peek Under The Hood - Brian Goetz
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Sdtl manual
Sdtl manualSdtl manual
Sdtl manual
 
CORBA IDL
CORBA IDLCORBA IDL
CORBA IDL
 
Understanding Reflection
Understanding ReflectionUnderstanding Reflection
Understanding Reflection
 
Extreme Interview Questions
Extreme Interview QuestionsExtreme Interview Questions
Extreme Interview Questions
 
Top 20 c# interview Question and answers
Top 20 c# interview Question and answersTop 20 c# interview Question and answers
Top 20 c# interview Question and answers
 
Core java Basics
Core java BasicsCore java Basics
Core java Basics
 
2. oop with c++ get 410 day 2
2. oop with c++ get 410   day 22. oop with c++ get 410   day 2
2. oop with c++ get 410 day 2
 
Java Programming | Java Tutorial For Beginners | Java Training | Edureka
Java Programming | Java Tutorial For Beginners | Java Training | EdurekaJava Programming | Java Tutorial For Beginners | Java Training | Edureka
Java Programming | Java Tutorial For Beginners | Java Training | Edureka
 
Moved to https://slidr.io/azzazzel/osgi-fundamentals
Moved to https://slidr.io/azzazzel/osgi-fundamentalsMoved to https://slidr.io/azzazzel/osgi-fundamentals
Moved to https://slidr.io/azzazzel/osgi-fundamentals
 
Java mcq
Java mcqJava mcq
Java mcq
 
50+ java interview questions
50+ java interview questions50+ java interview questions
50+ java interview questions
 
Java session05
Java session05Java session05
Java session05
 
Condor overview - glideinWMS Training Jan 2012
Condor overview - glideinWMS Training Jan 2012Condor overview - glideinWMS Training Jan 2012
Condor overview - glideinWMS Training Jan 2012
 

Ähnlich wie Messages, Instances and Initialization

Core java-course-content
Core java-course-contentCore java-course-content
Core java-course-contentAmanCSE1
 
Core java-training-course-content
Core java-training-course-contentCore java-training-course-content
Core java-training-course-contentvenkateshcs6
 
Core java-course-content
Core java-course-contentCore java-course-content
Core java-course-contentAmanCSE1
 
Java questions with answers
Java questions with answersJava questions with answers
Java questions with answersKuntal Bhowmick
 
Bca5020 visual programming
Bca5020  visual programmingBca5020  visual programming
Bca5020 visual programmingsmumbahelp
 
Bca5020 visual programming
Bca5020  visual programmingBca5020  visual programming
Bca5020 visual programmingsmumbahelp
 
Dynamic Language Performance
Dynamic Language PerformanceDynamic Language Performance
Dynamic Language PerformanceKevin Hazzard
 
Module 10 : creating and destroying objects
Module 10 : creating and destroying objectsModule 10 : creating and destroying objects
Module 10 : creating and destroying objectsPrem Kumar Badri
 
ActionScript 3.0 Fundamentals
ActionScript 3.0 FundamentalsActionScript 3.0 Fundamentals
ActionScript 3.0 FundamentalsSaurabh Narula
 
Javascriptinobject orientedway-090512225827-phpapp02
Javascriptinobject orientedway-090512225827-phpapp02Javascriptinobject orientedway-090512225827-phpapp02
Javascriptinobject orientedway-090512225827-phpapp02Sopheak Sem
 
Generation_XSD_Article.docx
Generation_XSD_Article.docxGeneration_XSD_Article.docx
Generation_XSD_Article.docxDavid Harrison
 
JavaScript Miller Columns
JavaScript Miller ColumnsJavaScript Miller Columns
JavaScript Miller ColumnsJonathan Fine
 
Smoothing Your Java with DSLs
Smoothing Your Java with DSLsSmoothing Your Java with DSLs
Smoothing Your Java with DSLsintelliyole
 
Drilling the Async Library
Drilling the Async LibraryDrilling the Async Library
Drilling the Async LibraryKnoldus Inc.
 

Ähnlich wie Messages, Instances and Initialization (20)

Core java-course-content
Core java-course-contentCore java-course-content
Core java-course-content
 
Core java-training-course-content
Core java-training-course-contentCore java-training-course-content
Core java-training-course-content
 
Core java-course-content
Core java-course-contentCore java-course-content
Core java-course-content
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Jvm internals
Jvm internalsJvm internals
Jvm internals
 
Java questions with answers
Java questions with answersJava questions with answers
Java questions with answers
 
Bca5020 visual programming
Bca5020  visual programmingBca5020  visual programming
Bca5020 visual programming
 
Bca5020 visual programming
Bca5020  visual programmingBca5020  visual programming
Bca5020 visual programming
 
Oopp Lab Work
Oopp Lab WorkOopp Lab Work
Oopp Lab Work
 
Dynamic Language Performance
Dynamic Language PerformanceDynamic Language Performance
Dynamic Language Performance
 
Module 10 : creating and destroying objects
Module 10 : creating and destroying objectsModule 10 : creating and destroying objects
Module 10 : creating and destroying objects
 
ActionScript 3.0 Fundamentals
ActionScript 3.0 FundamentalsActionScript 3.0 Fundamentals
ActionScript 3.0 Fundamentals
 
Javascriptinobject orientedway-090512225827-phpapp02
Javascriptinobject orientedway-090512225827-phpapp02Javascriptinobject orientedway-090512225827-phpapp02
Javascriptinobject orientedway-090512225827-phpapp02
 
Generation_XSD_Article.docx
Generation_XSD_Article.docxGeneration_XSD_Article.docx
Generation_XSD_Article.docx
 
JavaScript Miller Columns
JavaScript Miller ColumnsJavaScript Miller Columns
JavaScript Miller Columns
 
C# features
C# featuresC# features
C# features
 
Ch03
Ch03Ch03
Ch03
 
Ch03
Ch03Ch03
Ch03
 
Smoothing Your Java with DSLs
Smoothing Your Java with DSLsSmoothing Your Java with DSLs
Smoothing Your Java with DSLs
 
Drilling the Async Library
Drilling the Async LibraryDrilling the Async Library
Drilling the Async Library
 

Mehr von 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
 

Mehr von 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...
 

Kürzlich hochgeladen

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
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
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
 
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
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
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
 
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
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
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.
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
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
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 

Kürzlich hochgeladen (20)

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...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
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
 
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...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
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
 
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
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
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...
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
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
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 

Messages, Instances and Initialization

  • 1. Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References MESSAGES, INSTANCES AND INITIALIZATION Muhammad Adil Raja Roaming Researchers, Inc. cbna April 15, 2015 Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
  • 2. Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References OUTLINE I 1 INTRODUCTION 2 STATIC VS DYNAMIC 3 OBJECT CREATION 4 MEMORY ERRORS 5 CONSTRUCTORS 6 METACLASSES 7 SUMMARY 8 REFERENCES Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
  • 3. Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References INTRODUCTION I In the previous lesson we studied the static, or compile-time aspects of classes. In this lesson we shall study their run-time features. Message Passing Syntax. Object Creation and Initialization (constructors). Accessing the Receiver from within a method. Memory Management or garbage collection. Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
  • 4. Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References MESSAGES ARE NOT FUNCTION CALLS I Difference between a message and a function call. A message is always given to some object, called the receiver. The action performed in response is determined by the receiver, different receivers can do different actions in response to the same message. Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
  • 5. Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References MESSAGE PASSING SYNTAX I Although the syntax may differ in different langauges, all messages have three identifiable parts: MESSAGE SYNTAX aGame. displayCard ( aCard , 42 , 27); The message receiver. The message selector. An optional list of arguments. Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
  • 6. Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References STATICALLY TYPED VERSUS DYNAMICALLY TYPED LANGUAGES I A statically typed language requires the programmer to declare a type for each variable. The validity of a message passing expression will be checked at compile time, based on the declared type of the receiver. A dynamically typed language associates types with values, not with variables. A variable is just a name. The legality of a message cannot be determined until run-time. Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
  • 7. Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References THE RECEIVER VARIABLE I Inside a method, the receiver can be accessed by means of a pseudo-variable. Called this in Java, C++, C#. Called self in Smalltalk, Objective-C, Object Pascal. Called current in Eiffel. RECEIVER function PlayingCard . color : colors ; begin i f ( s e l f . s u i t = Heart ) or ( s e l f . s u i t = Diamond ) then color := Red else color := Black ; end Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
  • 8. Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References IMPLICIT USE OF THIS I Within a method a message expression or a data access with no explicit receiver is implicitly assumed to refer to this: RECEIVER class PlayingCard { . . . public void f l i p ( ) { setFaceUp ( ! faceUp ) ; } . . . } Is equivalent to: class PlayingCard { . . . public void f l i p ( ) { this . setFaceUp ( ! this . faceUp ) ; } . . . } Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
  • 9. Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References OBJECT CREATION I In most programming languages objects must be created dynamically, usually using the new operator: EXAMPLE OF USAGE OF NEW PlayingCard aCard ; / / simply names a new variable aCard = new PlayingCard ( Diamond , 3 ) ; / / creates the new object The declaration simply names a variable, the new operator is needed to create the new object value. Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
  • 10. Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References MEMORY RECOVERY I Because in most languages objects are dynamically allocated, they must be recovered at run-time. There are two broad approches to this: Force the programmer to explicitly say when a value is no longer being used: EXAMPLE OF DELETE delete aCard ; / / C++ example Use a garbage collection system that will automatically determine when values are no longer being used, and recover the memory. Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
  • 11. Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References MEMORY ERRORS I Garbage collection systems impose a run-time overhead, but prevent a number of potential memory errors: Running out of memory because the programmer forgot to free values Using a memory value after it has been recovered. MORE DELETE PlayingCard ∗ aCard = new PlayingCard (Spade , 1 ) ; delete aCard ; cout << aCard . rank ( ) ; Free the same value twice. Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
  • 12. Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References MEMORY ERRORS II DELETE CONTINUED PlayingCard ∗ aCard = new PlayingCard (Spade , 1 ) ; delete aCard ; delete aCard ; / / delete already deleted value Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
  • 13. Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References CONSTRUCTORS I A constructor is a function that is implicitly invoked when a new object is created. The constructor performs whatever actions are necessary in order to initialize the object. In C++, Java, C# a constructor is a function with the same name as the class. In Python constructors are all named – init. In Delphi, Objective-C, constructors have special syntax, but can be named anything. Naming your constructors create is a common convention. Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
  • 14. Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References CONSTRUCTORS II CONSTRUCTOR class PlayingCard { / / a Java constructor public PlayingCard ( int s , int r ) { s u i t = s ; rank = r ; faceUp = true ; } . . . } Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
  • 15. Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References OVERLOADED CONSTRUCTORS I Constructors are often overloaded, meaning there are a number of functions with the same name. They are differentiated by the type signature, and the arguments used in the function call or declaration: OVERLOADED CONSTRUCTOR Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
  • 16. Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References OVERLOADED CONSTRUCTORS II class PlayingCard { public : PlayingCard ( ) / / default constructor , / / used when no arguments are given { s u i t = Diamond ; rank = 1; faceUp = true ; } PlayingCard ( Suit i s ) / / constructor with one argument { s u i t = i s ; rank = 1; faceUp = true ; } PlayingCard ( Suit is , int i r ) / / constructor with two arguments { s u i t = i s ; rank = i r ; faceUp = true ; } } ; Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
  • 17. Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References METACLASSES I In Smalltalk (and Objective-C) classes are just objects, instances of class Class. new is just a message given to a class object. If we want to create constructors, where do we put them? They can’t be part of the collection of messages of instances of the class, since we don’t yet have an instance. They can’t be part of the messages understood by class Class, since not all classes have the same constructor message. Where do we put the behavior for individual class instances? Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
  • 18. Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References METACLASSES II The solution is to create a new class, whos only instance is itself a class. picture An elegant solution that maintains the simple instance/class relationship. Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
  • 19. Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References SUMMARY I In this chapter we have examined the following topics: Message Passing Syntax. Object Creation and Initialization (constructors). Accessing the Receiver from within a method. Memory Management or garbage collection. Metaclasses in Smalltalk. Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization
  • 20. Introduction Static vs Dynamic Object Creation Memory Errors Constructors Metaclasses Summary References REFERENCES I Images and content for developing these slides have been taken from the follwoing book. An Introduction to Object Oriented Programming, Timothy Budd. This presentation is developed using Beamer: Berlin, monarca. Muhammad Adil Raja Roaming Researchers, Inc. cbnaMessages, Instances and Initialization