SlideShare uma empresa Scribd logo
1 de 14
Baixar para ler offline
Dynamic Proxy by Java
2012/10/5 John
Agenda
● Motivation
● Run-Time Type Information
● Reflection
● ClassLoader
● Proxy Pattern
● Dynamic Proxy
● Example
● Summary
Motivation
Since we want to integral all of player in our
'AVMMediaPlayer' framework, then need to specified
framework API according by customer's requirement but
don't want much maintain cost...
Interface 1
ImpIementation
Interface 2 Interface 3 Interface 4
API 1 API 1API 2
Motivation
Problem:
1. Implementation's type is same to API.
2. Implementation is not implement interface directly.
3. That is strange of architecture.
Interface 1
ImpIementation
Interface 2 Interface 3 Interface 4
API 1 API 2
Run-Time Type Information
This mechanism can exposes information about an object's
data type at run-time. The C++ run-time type information
permits performing safe typecasts and manipulate type
information at run time.
Parent
Derived
Parent *p = new Derived;
Derived *d = dynamic_cast<Derived*>(p);
Ref: Wikipedia - http://en.wikipedia.org/wiki/Run-time_type_information
Reflection
Reflection is the ability of a computer program to examine
and modify the structure and behavior (specifically the
values, meta-data, properties and functions) of an object at
run-time.
Ref: Wikipedia - http://en.wikipedia.org/wiki/Reflection_(computer_programming)
Object Data or Method
Reflection (cont.)
A language supporting reflection provides a number of features
available at run-time that would otherwise be very obscure to
accomplish in a lower-level language. Some of these features are
the abilities to:
● Discover and modify source code constructions (such as code
blocks, classes, methods, protocols, etc.) as a first-class object
at run-time.
● Convert a string matching the symbolic name of a class or
function into a reference to or invocation of that class or
function.
● Evaluate a string as if it were a source code statement at run-
time.
● Create a new interpreter for the language's byte-code to give a
new meaning or purpose for a programming construct.
Ref: Wikipedia - http://en.wikipedia.org/wiki/Reflection_(computer_programming)
Reflection (cont.)
For example:
// Without reflection
new Foo().hello();
// With reflection
Class<?> clazz = Class.forName("Foo");
clazz.getMethod("hello").invoke(clazz.newInstance());
Ref: Wikipedia - http://en.wikipedia.org/wiki/Reflection_(computer_programming)
ObjectData or
Method
ClassLoader
The Java Classloader is a part of the Java Runtime Environment
that dynamically loads Java classes into the Java Virtual Machine.
Usually classes are only loaded on demand. The Java run time
system does not need to know about files and file systems because
of class loaders.
When the JVM is started, three class loaders are used:
● Bootstrap class loader (loads the core Java libraries located in the
<JAVA_HOME>/lib directory)
● Extensions class loader (loads the code in the extensions directories,
<JAVA_HOME>/lib/ext, or any other directory specified by the java.ext.dirs system
property)
● System class loader (loads code found on java.class.path, which maps to the
system CLASSPATH variable.)
Ref: Wikipedia - http://en.wikipedia.org/wiki/Java_Classloader
ClassLoader (cont.)
Briefly speaking the class loader is:
Class byte code => 'Class' object (class's reference)
Class A bytecode bytecode
Java
Compiler
Java
Classloader
Proxy Pattern
A proxy, in its most general form, is a class functioning as an interface to
something else. The proxy could interface to anything: a network connection, a
large object in memory, a file, or some other resource that is expensive or
impossible to duplicate.
Ref: Wikipedia - http://en.wikipedia.org/wiki/Proxy_pattern
Dynamic Proxy
Proxy is not Interface's instance, is reflecting to concrete interface's
implementation dynamically.
<<interface>>
Subject
RealSubject
Client
Dynamic Proxy
delegate
class
loader
class
Example
Independent with API and Implementation.
Interface 1
ImpIementation
Interface 2 Interface 3 Interface 4
API 1 API 2
Dynamic Proxy
Summary
● RTTI is saving type information at run time.
● Reflction mechanism can let we know a Object at run
time.
● In order to use a Object at run time need class loader.
● Achieve dynamic proxy.

Mais conteúdo relacionado

Mais procurados

Java class loading tips and tricks - Java Colombo Meetup, January, 2014
Java class loading  tips and tricks - Java Colombo Meetup, January, 2014Java class loading  tips and tricks - Java Colombo Meetup, January, 2014
Java class loading tips and tricks - Java Colombo Meetup, January, 2014
Sameera Jayasoma
 
Great cup of java
Great  cup of javaGreat  cup of java
Great cup of java
CIB Egypt
 
First-Class Undefined Classes for Pharo, From Alternative Designs to a Unifie...
First-Class Undefined Classes for Pharo, From Alternative Designs to a Unifie...First-Class Undefined Classes for Pharo, From Alternative Designs to a Unifie...
First-Class Undefined Classes for Pharo, From Alternative Designs to a Unifie...
ESUG
 
Do you really get class loaders?
Do you really get class loaders? Do you really get class loaders?
Do you really get class loaders?
guestd56374
 
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Christian Schneider
 

Mais procurados (20)

Understanding ClassLoaders
Understanding ClassLoadersUnderstanding ClassLoaders
Understanding ClassLoaders
 
Java class loading tips and tricks - Java Colombo Meetup, January, 2014
Java class loading  tips and tricks - Java Colombo Meetup, January, 2014Java class loading  tips and tricks - Java Colombo Meetup, January, 2014
Java class loading tips and tricks - Java Colombo Meetup, January, 2014
 
testing ppt
testing ppttesting ppt
testing ppt
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 
SyScan 2016 - Remote code execution via Java native deserialization
SyScan 2016 - Remote code execution via Java native deserializationSyScan 2016 - Remote code execution via Java native deserialization
SyScan 2016 - Remote code execution via Java native deserialization
 
Exploiting Deserialization Vulnerabilities in Java
Exploiting Deserialization Vulnerabilities in JavaExploiting Deserialization Vulnerabilities in Java
Exploiting Deserialization Vulnerabilities in Java
 
Java
JavaJava
Java
 
Great cup of java
Great  cup of javaGreat  cup of java
Great cup of java
 
Java Programming - 01 intro to java
Java Programming - 01 intro to javaJava Programming - 01 intro to java
Java Programming - 01 intro to java
 
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)
 
An Introduction to Java Compiler and Runtime
An Introduction to Java Compiler and RuntimeAn Introduction to Java Compiler and Runtime
An Introduction to Java Compiler and Runtime
 
First-Class Undefined Classes for Pharo, From Alternative Designs to a Unifie...
First-Class Undefined Classes for Pharo, From Alternative Designs to a Unifie...First-Class Undefined Classes for Pharo, From Alternative Designs to a Unifie...
First-Class Undefined Classes for Pharo, From Alternative Designs to a Unifie...
 
Java basic introduction
Java basic introductionJava basic introduction
Java basic introduction
 
Java Deserialization Vulnerabilities - The Forgotten Bug Class
Java Deserialization Vulnerabilities - The Forgotten Bug ClassJava Deserialization Vulnerabilities - The Forgotten Bug Class
Java Deserialization Vulnerabilities - The Forgotten Bug Class
 
Do you really get class loaders?
Do you really get class loaders? Do you really get class loaders?
Do you really get class loaders?
 
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
No locked doors, no windows barred: hacking OpenAM infrastructure
No locked doors, no windows barred: hacking OpenAM infrastructureNo locked doors, no windows barred: hacking OpenAM infrastructure
No locked doors, no windows barred: hacking OpenAM infrastructure
 
Ahead-Of-Time Compilation of Java Applications
Ahead-Of-Time Compilation of Java ApplicationsAhead-Of-Time Compilation of Java Applications
Ahead-Of-Time Compilation of Java Applications
 
Objective c runtime
Objective c runtimeObjective c runtime
Objective c runtime
 

Destaque

Object relationship mapping and hibernate
Object relationship mapping and hibernateObject relationship mapping and hibernate
Object relationship mapping and hibernate
Joe Jacob
 
Classloading and Type Visibility in OSGi
Classloading and Type Visibility in OSGiClassloading and Type Visibility in OSGi
Classloading and Type Visibility in OSGi
martinlippert
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
guest11106b
 

Destaque (10)

Proxy & CGLIB
Proxy & CGLIBProxy & CGLIB
Proxy & CGLIB
 
Object relationship mapping and hibernate
Object relationship mapping and hibernateObject relationship mapping and hibernate
Object relationship mapping and hibernate
 
Proxy deep-dive java-one_20151027_001
Proxy deep-dive java-one_20151027_001Proxy deep-dive java-one_20151027_001
Proxy deep-dive java-one_20151027_001
 
Classloading and Type Visibility in OSGi
Classloading and Type Visibility in OSGiClassloading and Type Visibility in OSGi
Classloading and Type Visibility in OSGi
 
hibernate with JPA
hibernate with JPAhibernate with JPA
hibernate with JPA
 
AWS CloudFormation en 5 Minutos
AWS CloudFormation en 5 MinutosAWS CloudFormation en 5 Minutos
AWS CloudFormation en 5 Minutos
 
Understanding Java Dynamic Proxies
Understanding Java Dynamic ProxiesUnderstanding Java Dynamic Proxies
Understanding Java Dynamic Proxies
 
Hibernate in Action
Hibernate in ActionHibernate in Action
Hibernate in Action
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
55 New Features in Java 7
55 New Features in Java 755 New Features in Java 7
55 New Features in Java 7
 

Semelhante a Dynamic Proxy by Java

A begineers guide of JAVA - Getting Started
 A begineers guide of JAVA - Getting Started A begineers guide of JAVA - Getting Started
A begineers guide of JAVA - Getting Started
Rakesh Madugula
 
Java-1st.pptx about Java technology before oops
Java-1st.pptx about Java technology before oopsJava-1st.pptx about Java technology before oops
Java-1st.pptx about Java technology before oops
buvanabala
 
Java Interview Questions Answers Guide
Java Interview Questions Answers GuideJava Interview Questions Answers Guide
Java Interview Questions Answers Guide
DaisyWatson5
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
Nexus
 

Semelhante a Dynamic Proxy by Java (20)

A begineers guide of JAVA - Getting Started
 A begineers guide of JAVA - Getting Started A begineers guide of JAVA - Getting Started
A begineers guide of JAVA - Getting Started
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
 
Java-1st.pptx about Java technology before oops
Java-1st.pptx about Java technology before oopsJava-1st.pptx about Java technology before oops
Java-1st.pptx about Java technology before oops
 
CS8392 OOP
CS8392 OOPCS8392 OOP
CS8392 OOP
 
Basic java part_ii
Basic java part_iiBasic java part_ii
Basic java part_ii
 
JAVA for Every one
JAVA for Every oneJAVA for Every one
JAVA for Every one
 
oop unit1.pptx
oop unit1.pptxoop unit1.pptx
oop unit1.pptx
 
j-chap1-Basics.ppt
j-chap1-Basics.pptj-chap1-Basics.ppt
j-chap1-Basics.ppt
 
Java programming basics
Java programming basicsJava programming basics
Java programming basics
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introduction
 
Java basic
Java basicJava basic
Java basic
 
Java For beginners and CSIT and IT students
Java  For beginners and CSIT and IT studentsJava  For beginners and CSIT and IT students
Java For beginners and CSIT and IT students
 
OOP with Java
OOP with JavaOOP with Java
OOP with Java
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
Java Interview Questions Answers Guide
Java Interview Questions Answers GuideJava Interview Questions Answers Guide
Java Interview Questions Answers Guide
 
Java 8 Overview
Java 8 OverviewJava 8 Overview
Java 8 Overview
 
Java unit 1
Java unit 1Java unit 1
Java unit 1
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
Java programming basics notes for beginners(java programming tutorials)
Java programming basics notes for beginners(java programming tutorials)Java programming basics notes for beginners(java programming tutorials)
Java programming basics notes for beginners(java programming tutorials)
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 

Mais de Kan-Han (John) Lu

Mais de Kan-Han (John) Lu (20)

Dagger for android
Dagger for androidDagger for android
Dagger for android
 
Android develop guideline
Android develop guidelineAndroid develop guideline
Android develop guideline
 
Working process and git branch strategy
Working process and git branch strategyWorking process and git branch strategy
Working process and git branch strategy
 
Deep neural network for youtube recommendations
Deep neural network for youtube recommendationsDeep neural network for youtube recommendations
Deep neural network for youtube recommendations
 
Android testing part i
Android testing part iAndroid testing part i
Android testing part i
 
Cuda project paper
Cuda project paperCuda project paper
Cuda project paper
 
Twitter as a personalizable information service ii
Twitter as a personalizable information service iiTwitter as a personalizable information service ii
Twitter as a personalizable information service ii
 
Multimedia data minig and analytics sentiment analysis using social multimedia
Multimedia data minig and analytics sentiment analysis using social multimediaMultimedia data minig and analytics sentiment analysis using social multimedia
Multimedia data minig and analytics sentiment analysis using social multimedia
 
Android IPC: Binder
Android IPC: BinderAndroid IPC: Binder
Android IPC: Binder
 
ARM: Trusted Zone on Android
ARM: Trusted Zone on AndroidARM: Trusted Zone on Android
ARM: Trusted Zone on Android
 
Android Training - Card Style
Android Training - Card StyleAndroid Training - Card Style
Android Training - Card Style
 
Android Training - View Pager
Android Training - View PagerAndroid Training - View Pager
Android Training - View Pager
 
Android Training - Sliding Menu
Android Training - Sliding MenuAndroid Training - Sliding Menu
Android Training - Sliding Menu
 
Android Training - Pull to Refresh
Android Training - Pull to RefreshAndroid Training - Pull to Refresh
Android Training - Pull to Refresh
 
Java: Exception Handling
Java: Exception HandlingJava: Exception Handling
Java: Exception Handling
 
Code analyzer: FindBugs and PMD
Code analyzer: FindBugs and PMDCode analyzer: FindBugs and PMD
Code analyzer: FindBugs and PMD
 
Android UI System
Android UI SystemAndroid UI System
Android UI System
 
Android Fragment
Android FragmentAndroid Fragment
Android Fragment
 
Android Training - Content Sharing
Android Training - Content SharingAndroid Training - Content Sharing
Android Training - Content Sharing
 
Android Training - Action Bar
Android Training - Action BarAndroid Training - Action Bar
Android Training - Action Bar
 

Último

Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Lokesh Kothari
 
Presentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxPresentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptx
gindu3009
 
Formation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksFormation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disks
Sérgio Sacani
 
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune WaterworldsBiogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Sérgio Sacani
 
Bacterial Identification and Classifications
Bacterial Identification and ClassificationsBacterial Identification and Classifications
Bacterial Identification and Classifications
Areesha Ahmad
 
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
ssuser79fe74
 
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 bAsymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Sérgio Sacani
 

Último (20)

Recombinant DNA technology (Immunological screening)
Recombinant DNA technology (Immunological screening)Recombinant DNA technology (Immunological screening)
Recombinant DNA technology (Immunological screening)
 
Botany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfBotany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdf
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
 
Presentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxPresentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptx
 
Botany krishna series 2nd semester Only Mcq type questions
Botany krishna series 2nd semester Only Mcq type questionsBotany krishna series 2nd semester Only Mcq type questions
Botany krishna series 2nd semester Only Mcq type questions
 
Formation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksFormation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disks
 
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune WaterworldsBiogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
 
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bNightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
 
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
 
Bacterial Identification and Classifications
Bacterial Identification and ClassificationsBacterial Identification and Classifications
Bacterial Identification and Classifications
 
Pulmonary drug delivery system M.pharm -2nd sem P'ceutics
Pulmonary drug delivery system M.pharm -2nd sem P'ceuticsPulmonary drug delivery system M.pharm -2nd sem P'ceutics
Pulmonary drug delivery system M.pharm -2nd sem P'ceutics
 
COST ESTIMATION FOR A RESEARCH PROJECT.pptx
COST ESTIMATION FOR A RESEARCH PROJECT.pptxCOST ESTIMATION FOR A RESEARCH PROJECT.pptx
COST ESTIMATION FOR A RESEARCH PROJECT.pptx
 
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCRStunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
 
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
 
GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)
 
VIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C PVIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C P
 
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
 
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
 
GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)
 
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 bAsymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
 

Dynamic Proxy by Java

  • 1. Dynamic Proxy by Java 2012/10/5 John
  • 2. Agenda ● Motivation ● Run-Time Type Information ● Reflection ● ClassLoader ● Proxy Pattern ● Dynamic Proxy ● Example ● Summary
  • 3. Motivation Since we want to integral all of player in our 'AVMMediaPlayer' framework, then need to specified framework API according by customer's requirement but don't want much maintain cost... Interface 1 ImpIementation Interface 2 Interface 3 Interface 4 API 1 API 1API 2
  • 4. Motivation Problem: 1. Implementation's type is same to API. 2. Implementation is not implement interface directly. 3. That is strange of architecture. Interface 1 ImpIementation Interface 2 Interface 3 Interface 4 API 1 API 2
  • 5. Run-Time Type Information This mechanism can exposes information about an object's data type at run-time. The C++ run-time type information permits performing safe typecasts and manipulate type information at run time. Parent Derived Parent *p = new Derived; Derived *d = dynamic_cast<Derived*>(p); Ref: Wikipedia - http://en.wikipedia.org/wiki/Run-time_type_information
  • 6. Reflection Reflection is the ability of a computer program to examine and modify the structure and behavior (specifically the values, meta-data, properties and functions) of an object at run-time. Ref: Wikipedia - http://en.wikipedia.org/wiki/Reflection_(computer_programming) Object Data or Method
  • 7. Reflection (cont.) A language supporting reflection provides a number of features available at run-time that would otherwise be very obscure to accomplish in a lower-level language. Some of these features are the abilities to: ● Discover and modify source code constructions (such as code blocks, classes, methods, protocols, etc.) as a first-class object at run-time. ● Convert a string matching the symbolic name of a class or function into a reference to or invocation of that class or function. ● Evaluate a string as if it were a source code statement at run- time. ● Create a new interpreter for the language's byte-code to give a new meaning or purpose for a programming construct. Ref: Wikipedia - http://en.wikipedia.org/wiki/Reflection_(computer_programming)
  • 8. Reflection (cont.) For example: // Without reflection new Foo().hello(); // With reflection Class<?> clazz = Class.forName("Foo"); clazz.getMethod("hello").invoke(clazz.newInstance()); Ref: Wikipedia - http://en.wikipedia.org/wiki/Reflection_(computer_programming) ObjectData or Method
  • 9. ClassLoader The Java Classloader is a part of the Java Runtime Environment that dynamically loads Java classes into the Java Virtual Machine. Usually classes are only loaded on demand. The Java run time system does not need to know about files and file systems because of class loaders. When the JVM is started, three class loaders are used: ● Bootstrap class loader (loads the core Java libraries located in the <JAVA_HOME>/lib directory) ● Extensions class loader (loads the code in the extensions directories, <JAVA_HOME>/lib/ext, or any other directory specified by the java.ext.dirs system property) ● System class loader (loads code found on java.class.path, which maps to the system CLASSPATH variable.) Ref: Wikipedia - http://en.wikipedia.org/wiki/Java_Classloader
  • 10. ClassLoader (cont.) Briefly speaking the class loader is: Class byte code => 'Class' object (class's reference) Class A bytecode bytecode Java Compiler Java Classloader
  • 11. Proxy Pattern A proxy, in its most general form, is a class functioning as an interface to something else. The proxy could interface to anything: a network connection, a large object in memory, a file, or some other resource that is expensive or impossible to duplicate. Ref: Wikipedia - http://en.wikipedia.org/wiki/Proxy_pattern
  • 12. Dynamic Proxy Proxy is not Interface's instance, is reflecting to concrete interface's implementation dynamically. <<interface>> Subject RealSubject Client Dynamic Proxy delegate class loader class
  • 13. Example Independent with API and Implementation. Interface 1 ImpIementation Interface 2 Interface 3 Interface 4 API 1 API 2 Dynamic Proxy
  • 14. Summary ● RTTI is saving type information at run time. ● Reflction mechanism can let we know a Object at run time. ● In order to use a Object at run time need class loader. ● Achieve dynamic proxy.