SlideShare ist ein Scribd-Unternehmen logo
1 von 14
Downloaden Sie, um offline zu lesen
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.

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von Kan-Han (John) Lu

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

Kürzlich hochgeladen

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
 
Module for Grade 9 for Asynchronous/Distance learning
Module for Grade 9 for Asynchronous/Distance learningModule for Grade 9 for Asynchronous/Distance learning
Module for Grade 9 for Asynchronous/Distance learning
levieagacer
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
LUNULARIA -features, morphology, anatomy ,reproduction etc.
LUNULARIA -features, morphology, anatomy ,reproduction etc.LUNULARIA -features, morphology, anatomy ,reproduction etc.
LUNULARIA -features, morphology, anatomy ,reproduction etc.
Silpa
 
biology HL practice questions IB BIOLOGY
biology HL practice questions IB BIOLOGYbiology HL practice questions IB BIOLOGY
biology HL practice questions IB BIOLOGY
1301aanya
 
POGONATUM : morphology, anatomy, reproduction etc.
POGONATUM : morphology, anatomy, reproduction etc.POGONATUM : morphology, anatomy, reproduction etc.
POGONATUM : morphology, anatomy, reproduction etc.
Silpa
 
Digital Dentistry.Digital Dentistryvv.pptx
Digital Dentistry.Digital Dentistryvv.pptxDigital Dentistry.Digital Dentistryvv.pptx
Digital Dentistry.Digital Dentistryvv.pptx
MohamedFarag457087
 

Kürzlich hochgeladen (20)

Thyroid Physiology_Dr.E. Muralinath_ Associate Professor
Thyroid Physiology_Dr.E. Muralinath_ Associate ProfessorThyroid Physiology_Dr.E. Muralinath_ Associate Professor
Thyroid Physiology_Dr.E. Muralinath_ Associate Professor
 
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
 
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
 
module for grade 9 for distance learning
module for grade 9 for distance learningmodule for grade 9 for distance learning
module for grade 9 for distance learning
 
Gwalior ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Gwalior ESCORT SERVICE❤CALL GIRL
Gwalior ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Gwalior ESCORT SERVICE❤CALL GIRLGwalior ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Gwalior ESCORT SERVICE❤CALL GIRL
Gwalior ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Gwalior ESCORT SERVICE❤CALL GIRL
 
GBSN - Microbiology (Unit 3)
GBSN - Microbiology (Unit 3)GBSN - Microbiology (Unit 3)
GBSN - Microbiology (Unit 3)
 
Module for Grade 9 for Asynchronous/Distance learning
Module for Grade 9 for Asynchronous/Distance learningModule for Grade 9 for Asynchronous/Distance learning
Module for Grade 9 for Asynchronous/Distance learning
 
Cyanide resistant respiration pathway.pptx
Cyanide resistant respiration pathway.pptxCyanide resistant respiration pathway.pptx
Cyanide resistant respiration pathway.pptx
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Factory Acceptance Test( FAT).pptx .
Factory Acceptance Test( FAT).pptx       .Factory Acceptance Test( FAT).pptx       .
Factory Acceptance Test( FAT).pptx .
 
LUNULARIA -features, morphology, anatomy ,reproduction etc.
LUNULARIA -features, morphology, anatomy ,reproduction etc.LUNULARIA -features, morphology, anatomy ,reproduction etc.
LUNULARIA -features, morphology, anatomy ,reproduction etc.
 
TransientOffsetin14CAftertheCarringtonEventRecordedbyPolarTreeRings
TransientOffsetin14CAftertheCarringtonEventRecordedbyPolarTreeRingsTransientOffsetin14CAftertheCarringtonEventRecordedbyPolarTreeRings
TransientOffsetin14CAftertheCarringtonEventRecordedbyPolarTreeRings
 
Proteomics: types, protein profiling steps etc.
Proteomics: types, protein profiling steps etc.Proteomics: types, protein profiling steps etc.
Proteomics: types, protein profiling steps etc.
 
Molecular markers- RFLP, RAPD, AFLP, SNP etc.
Molecular markers- RFLP, RAPD, AFLP, SNP etc.Molecular markers- RFLP, RAPD, AFLP, SNP etc.
Molecular markers- RFLP, RAPD, AFLP, SNP etc.
 
300003-World Science Day For Peace And Development.pptx
300003-World Science Day For Peace And Development.pptx300003-World Science Day For Peace And Development.pptx
300003-World Science Day For Peace And Development.pptx
 
biology HL practice questions IB BIOLOGY
biology HL practice questions IB BIOLOGYbiology HL practice questions IB BIOLOGY
biology HL practice questions IB BIOLOGY
 
Site Acceptance Test .
Site Acceptance Test                    .Site Acceptance Test                    .
Site Acceptance Test .
 
Role of AI in seed science Predictive modelling and Beyond.pptx
Role of AI in seed science  Predictive modelling and  Beyond.pptxRole of AI in seed science  Predictive modelling and  Beyond.pptx
Role of AI in seed science Predictive modelling and Beyond.pptx
 
POGONATUM : morphology, anatomy, reproduction etc.
POGONATUM : morphology, anatomy, reproduction etc.POGONATUM : morphology, anatomy, reproduction etc.
POGONATUM : morphology, anatomy, reproduction etc.
 
Digital Dentistry.Digital Dentistryvv.pptx
Digital Dentistry.Digital Dentistryvv.pptxDigital Dentistry.Digital Dentistryvv.pptx
Digital Dentistry.Digital Dentistryvv.pptx
 

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.