SlideShare a Scribd company logo
Adapter

SENG 609.04 Design Patterns

         Winter, 2003



     Presented by Ming Zhou, Guy Davis
Agenda
      Intent & Motivation
  

      Structure
  

      Applicability
  

      Consequences
  

      Known Uses
  

      Related Patterns
  

      References
  

               - Total 17 pages -   1
What is Adapter?
    Change the interface of a


    class into another interface
    which is expected by the
    client.
    A.K.A. Wrapper





                  - Total 17 pages -   1
What is Adapter?
    Change the interface of a


    class into another interface
    which is expected by the
    client.
    A.K.A. Wrapper





                  - Total 17 pages -   1
What is Adapter?
    Change the interface of a


    class into another interface
    which is expected by the
    client.
    A.K.A. Wrapper





                  - Total 17 pages -   1
Motivation




             - Total 17 pages -   1
Motivation




             - Total 17 pages -   1
Motivation




             - Total 17 pages -   1
Motivation




                                  1   1



             - Total 17 pages -           1
Structure (Class)




           - Total 17 pages -   1
Structure (Object)




           - Total 17 pages -   1
Applicability




            - Total 17 pages -   1
Applicability
    Use an existing class whose interface


    does not match the requirement




                 - Total 17 pages -         1
Applicability
    Use an existing class whose interface


    does not match the requirement
    Create a reusable class though the


    interfaces are not necessary
    compatible with callers




                 - Total 17 pages -         1
Applicability
  Use an existing class whose interface


  does not match the requirement
 Create a reusable class though the

  interfaces are not necessary
  compatible with callers
 Want to use several existing subclasses,
  but it is impractical to subclass
  everyone. (Object Adapter Only)


               - Total 17 pages -       1
Class Adapter Pattern
    Pros


        Only 1 new object, no additional indirection
    


        Less code required than the object Adapter
    


        Can override Adaptee's behaviour as required
    



    Cons


        Requires sub-classing (tough for single
    


        inheritance)
        Less flexible than object Adapter
    




                       - Total 17 pages -              1
Object Adapter Pattern
      Pros
  

          More flexible than class Adapter
      


          Doesn't require sub-classing to work
      


          Adapter works with Adaptee and all of its
      

          subclasses
      Cons
  

          Harder to override Adaptee behavior
      


          Requires more code to implement
      

          properly

                         - Total 17 pages -           1
Pluggable Adapters




    implemented with abstract operations



                   - Total 17 pages -      1
Pluggable Adapters




    implemented with delegate objects

                    - Total 17 pages -   1
Two-way Adapters
                                               class PegAdapter: public SquarePeg,
class SquarePeg {
                                                  RoundPeg {
  public:
    void virtual squarePegOperation()              public:
   { blah }
                                                     void virtual roundPegOperation() {
}
                                                         add some corners;
                                                         squarePegOperation();
class RoundPeg {
                                                     }
    public:
                                                     void virtual squarePegOperation() {
      void virtual roundPegOperation()
                                                         add some corners;
     { blah }
                                                         roundPegOperation();
}
                                                     }
                                               }
                                     - Total 17 pages -                               1
Adapting Local Classes to RMI
Comparison:
 Increases reusability

  of local class
 Improves performance

  of local class
 Doesn't use Java

  single parent by
  subclassing (uses
  composition)
                  - Total 17 pages -   1
Related Patterns
    Adapter can be similar to the remote


    form of Proxy. However, Proxy doesn't
    change interfaces.
    Decorator enhances another object


    without changing its interface.
    Bridge similar structure to Adapter,


    but different intent. Separates
    interface from implementation.
                 - Total 17 pages -         1
Conclusions
    Allows collaboration between classes


    with incompatible interfaces
    Implemented in either class-based


    (inheritance) or object-based
    (composition & delegation) manner
    Useful pattern which promotes reuse


    and allows integration of diverse
    software components
                 - Total 17 pages -        1
References
    Becker, Dan. Design networked applications in RMI using the Adapter design




    pattern. JavaWorld Magazine, May 1999. http://www.javaworld.com/javaworld/
    jw-05-1999/jw-05-networked.html
    Buschmann et al. A System of Patterns: Pattern-Oriented Software Architecture.




    John Wiley and Sons. Chichester. 1996
    Gamma et al. Design Patterns: Elements of Reusable Object-Oriented Software.




    Addison-Wesley. Boston. 1995
    Nguyen, D.X. Tutorial 10: Stacks and Queues: The Adapter Pattern. Rice




    University. 1999. http://www.owlnet.rice.edu/~comp212/99-fall/tutorials/10/
    tutorial10.html
    Whitney, Roger. CS 635 Advanced Object-Oriented Design & Programming. San




    Diego State University. 2001. http://www.eli.sdsu.edu/courses/spring01/cs635/
    notes/proxy/proxy.html#Heading10
    Shalloway, Alan., and Trott, James R., Design Patterns Explained: A New




    Perspective on Object-Oriented Design, Addison-Wesley, 2002.
    Rising, Linda., The Patterns Handbook: Techniques, Strategies, and Applications,




    Cambridge university Press, 1998.


                                     - Total 17 pages -                                1
Questions?




             - Total 17 pages -   1
Questions?




             - Total 17 pages -   1
Java Native Interface (JNI)

SENG 609.04 Design Patterns

Winter, 2003



       Presented by Guy Davis, Ming Zhou
Agenda
      Overview
  

      Justification
  

      Hello World!
  

      Summary
  

      References
  

      Q&A
  




                - Total 17 pages -   1
JNI Overview




          - Total 17 pages -   1
Interactions with Native Code



      Access to Java world from native code




      Access to- native code from Java
                 Total 17 pages -             1
Justification
Pros:
 Reuse: allows access to useful native code
 Efficiency: use best language for the task
Cons:
 Applets: doesn't work as they're mobile
 Portability: native methods aren't portable
 Extra work: javah, create shared native libs

                  - Total 17 pages -         1
HelloWorld.java
class HelloWorld {
public native void displayHelloWorld();
static {
    System.loadLibrary(quot;helloquot;);
}
public static void main(String[] args) {
    new
    HelloWorld().displayHelloWorld();
  }
}
               - Total 17 pages -     1
HelloWorld.java
class HelloWorld {
public native void displayHelloWorld();
static {
    System.loadLibrary(quot;helloquot;);
}
public static void main(String[] args) {
    new
    HelloWorld().displayHelloWorld();
  }
}
               - Total 17 pages -     1
HelloWorld.java
class HelloWorld {
public native void displayHelloWorld();
static {
    System.loadLibrary(quot;helloquot;);
}
public static void main(String[] args) {
    new
    HelloWorld().displayHelloWorld();
  }
}
               - Total 17 pages -     1
HelloWorld.java
class HelloWorld {
public native void displayHelloWorld();
static {
    System.loadLibrary(quot;helloquot;);
}
public static void main(String[] args) {
    new
    HelloWorld().displayHelloWorld();
  }
}
               - Total 17 pages -     1
HelloWorld.h
#include “jni.h”
/* Header for class HelloWorld */
#ifndef _Included_HelloWorld
#define _Included_HelloWorld
#ifdef __cplusplus
    extern “C” {
#endif

/*
 * Class: HelloWorld
 * Method: displayHelloWorld
 * Signature: ()V
 */
JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

                     - Total 17 pages -             1
HelloWorld.h
#include “jni.h”
/* Header for class HelloWorld */
#ifndef _Included_HelloWorld
#define _Included_HelloWorld
#ifdef __cplusplus
    extern “C” {
#endif

/*
 * Class: HelloWorld
 * Method: displayHelloWorld
 * Signature: ()V
 */
JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

                     - Total 17 pages -             1
HelloWorld.h
#include “jni.h”
/* Header for class HelloWorld */
#ifndef _Included_HelloWorld
#define _Included_HelloWorld
#ifdef __cplusplus
    extern “C” {
#endif

/*
 * Class: HelloWorld
 * Method: displayHelloWorld
 * Signature: ()V
 */
JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

                     - Total 17 pages -             1
HelloWorldImp.c

#include <jni.h>
#include quot;HelloWorld.hquot;
#include <stdio.h>

JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
{
    printf(quot;Hello world!nquot;);
    return;
}




                          - Total 17 pages -           1
HelloWorldImp.c

#include <jni.h>
#include quot;HelloWorld.hquot;
#include <stdio.h>

JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
{
    printf(quot;Hello world!nquot;);
    return;
}




                          - Total 17 pages -           1
HelloWorldImp.c

#include <jni.h>
#include quot;HelloWorld.hquot;
#include <stdio.h>

JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
{
    printf(quot;Hello world!nquot;);
    return;
}




                          - Total 17 pages -           1
HelloWorldImp.c

#include <jni.h>
#include quot;HelloWorld.hquot;
#include <stdio.h>

JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
{
    printf(quot;Hello world!nquot;);
    return;
}




                          - Total 17 pages -           1
Create a Shared Library
class HelloWorld {
   ...
        System.loadLibrary(quot;helloquot;);
   ...
}

 Compile the native code into a shared library:
  (example for MS Windows Visual C++ 4.0)


  cl -Ic:javainclude -Ic:javaincludewin32
     -LD HelloWorldImp.c -Fehello.dll



                            - Total 17 pages -   1
Run the Program
Command:

 java HelloWorld
Result:

 Hello World!

Possible
exceptions:

 java.lang.UnsatisfiedLinkError: no hello in
  shared library path at
  java.lang.Runtime.loadLibrary(Runtime.java)
  at java.lang.System.loadLibrary(System.java)
  at java.lang.Thread.init(Thread.java)


                    - Total 17 pages -      1
Summary
    Connect Java with native languages
    Code reuse
    Powerful
    Compromise of Java safety features,


    cross-platform and dynamic ability
    JNI call is slow and costful


    Not work well for applets



                 - Total 17 pages -       1
References
 Glenn L. Vanderburg. et al., Tricks of the Java
    Programming Gurus, 1996, http://docs.rinet.ru:8080/
    JaTricks/
   Beth Stearns, Trail: Java Native Interface, Sun
    Microsystems, Inc., 2003, http://java.sun.com/docs/
    books/tutorial/native1.1/
   Roedy Green, JNI, The Java Native Interface, Canadian
    Mind Products, 2002, http://mindprod.com/jni.html
   Kong Wenyu, A Brief Introduction to Java Native
    Interface, http://www.geocities.com/kongwenyu/jni.html


                       - Total 17 pages -               1
Questions?




             - Total 17 pages -   1
Questions?




             - Total 17 pages -   1

More Related Content

What's hot

Mediator pattern
Mediator patternMediator pattern
Mediator pattern
Shakil Ahmed
 
ADO.NET
ADO.NETADO.NET
ADO.NET
Wani Zahoor
 
Design patterns tutorials
Design patterns tutorialsDesign patterns tutorials
Design patterns tutorials
University of Technology
 
Solid principles
Solid principlesSolid principles
Solid principles
Toan Nguyen
 
Solid Principles
Solid PrinciplesSolid Principles
Solid Principles
humayunlkhan
 
Jdbc complete
Jdbc completeJdbc complete
Jdbc complete
Sandeep Rawat
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
prabhu rajendran
 
Decorator Design Pattern
Decorator Design PatternDecorator Design Pattern
Decorator Design Pattern
Adeel Riaz
 
Solid principles
Solid principlesSolid principles
Solid principles
Declan Whelan
 
Entity Relationship Diagram presentation
Entity Relationship Diagram presentationEntity Relationship Diagram presentation
Entity Relationship Diagram presentation
Sopov Chan
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method Pattern
Anjan Kumar Bollam
 
GRID VIEW PPT
GRID VIEW PPTGRID VIEW PPT
Composite pattern
Composite patternComposite pattern
Composite pattern
Shakil Ahmed
 
Builder pattern
Builder patternBuilder pattern
Builder pattern
Shakil Ahmed
 
Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)
paramisoft
 
Prototype pattern
Prototype patternPrototype pattern
Prototype pattern
Shakil Ahmed
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programming
Kumar
 
Methods in C#
Methods in C#Methods in C#
Methods in C#
Prasanna Kumar SM
 
Clean code: SOLID
Clean code: SOLIDClean code: SOLID
Clean code: SOLID
Indeema Software Inc.
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
Pankhuree Srivastava
 

What's hot (20)

Mediator pattern
Mediator patternMediator pattern
Mediator pattern
 
ADO.NET
ADO.NETADO.NET
ADO.NET
 
Design patterns tutorials
Design patterns tutorialsDesign patterns tutorials
Design patterns tutorials
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Solid Principles
Solid PrinciplesSolid Principles
Solid Principles
 
Jdbc complete
Jdbc completeJdbc complete
Jdbc complete
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
 
Decorator Design Pattern
Decorator Design PatternDecorator Design Pattern
Decorator Design Pattern
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Entity Relationship Diagram presentation
Entity Relationship Diagram presentationEntity Relationship Diagram presentation
Entity Relationship Diagram presentation
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method Pattern
 
GRID VIEW PPT
GRID VIEW PPTGRID VIEW PPT
GRID VIEW PPT
 
Composite pattern
Composite patternComposite pattern
Composite pattern
 
Builder pattern
Builder patternBuilder pattern
Builder pattern
 
Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)
 
Prototype pattern
Prototype patternPrototype pattern
Prototype pattern
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programming
 
Methods in C#
Methods in C#Methods in C#
Methods in C#
 
Clean code: SOLID
Clean code: SOLIDClean code: SOLID
Clean code: SOLID
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 

Viewers also liked

ennaji ahmed base de donnees
ennaji ahmed base de donneesennaji ahmed base de donnees
ennaji ahmed base de donnees
AHMED ENNAJI
 
Design Patterns - 01 Introduction and Decorator Pattern
Design Patterns - 01 Introduction and Decorator PatternDesign Patterns - 01 Introduction and Decorator Pattern
Design Patterns - 01 Introduction and Decorator Pattern
eprafulla
 
Composite Design Pattern
Composite Design PatternComposite Design Pattern
Composite Design Pattern
Ferdous Mahmud Shaon
 
The Decorator Pattern
The Decorator PatternThe Decorator Pattern
The Decorator Pattern
Akshat Vig
 
Composite Pattern
Composite PatternComposite Pattern
Composite Pattern
Somenath Mukhopadhyay
 
Design Pattern
Design PatternDesign Pattern
Design Pattern
Himanshu
 
Behavioral pattern By:-Priyanka Pradhan
Behavioral pattern By:-Priyanka PradhanBehavioral pattern By:-Priyanka Pradhan
Behavioral pattern By:-Priyanka Pradhan
Priyanka Pradhan
 
Creational pattern
Creational patternCreational pattern
Creational pattern
Himanshu
 
Decorator design pattern (A Gift Wrapper)
Decorator design pattern (A Gift Wrapper)Decorator design pattern (A Gift Wrapper)
Decorator design pattern (A Gift Wrapper)
Sameer Rathoud
 
Security and Integrity of Data
Security and Integrity of DataSecurity and Integrity of Data
Security and Integrity of Data
Adeel Riaz
 
Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns ppt
Aman Jain
 
Structural patterns
Structural patternsStructural patterns
Structural patterns
Himanshu
 

Viewers also liked (12)

ennaji ahmed base de donnees
ennaji ahmed base de donneesennaji ahmed base de donnees
ennaji ahmed base de donnees
 
Design Patterns - 01 Introduction and Decorator Pattern
Design Patterns - 01 Introduction and Decorator PatternDesign Patterns - 01 Introduction and Decorator Pattern
Design Patterns - 01 Introduction and Decorator Pattern
 
Composite Design Pattern
Composite Design PatternComposite Design Pattern
Composite Design Pattern
 
The Decorator Pattern
The Decorator PatternThe Decorator Pattern
The Decorator Pattern
 
Composite Pattern
Composite PatternComposite Pattern
Composite Pattern
 
Design Pattern
Design PatternDesign Pattern
Design Pattern
 
Behavioral pattern By:-Priyanka Pradhan
Behavioral pattern By:-Priyanka PradhanBehavioral pattern By:-Priyanka Pradhan
Behavioral pattern By:-Priyanka Pradhan
 
Creational pattern
Creational patternCreational pattern
Creational pattern
 
Decorator design pattern (A Gift Wrapper)
Decorator design pattern (A Gift Wrapper)Decorator design pattern (A Gift Wrapper)
Decorator design pattern (A Gift Wrapper)
 
Security and Integrity of Data
Security and Integrity of DataSecurity and Integrity of Data
Security and Integrity of Data
 
Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns ppt
 
Structural patterns
Structural patternsStructural patterns
Structural patterns
 

Similar to Adapter Design Pattern

Adapter Pattern Abhijit Hiremagalur 200603
Adapter Pattern Abhijit Hiremagalur 200603Adapter Pattern Abhijit Hiremagalur 200603
Adapter Pattern Abhijit Hiremagalur 200603
melbournepatterns
 
Creational Design Patterns
Creational Design PatternsCreational Design Patterns
Creational Design Patterns
Jamie (Taka) Wang
 
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
Codemotion
 
jdays 2015
jdays 2015jdays 2015
jdays 2015
Joe Kutner
 
Anti Object-Oriented Design Patterns
Anti Object-Oriented Design PatternsAnti Object-Oriented Design Patterns
Anti Object-Oriented Design Patterns
Alvaro Polo Valdenebro
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React Native
Waqqas Jabbar
 
Visage Android Hands-on Lab (OSCON)
Visage Android Hands-on Lab (OSCON)Visage Android Hands-on Lab (OSCON)
Visage Android Hands-on Lab (OSCON)
Stephen Chin
 
Lecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Lecture 8 - Qooxdoo - Rap Course At The University Of SzegedLecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Lecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Fabian Jakobs
 
Redux vs GraphQL
Redux vs GraphQLRedux vs GraphQL
Redux vs GraphQL
Jordon McKoy
 
Laird Best Practices Ajax World West2008
Laird Best Practices Ajax World West2008Laird Best Practices Ajax World West2008
Laird Best Practices Ajax World West2008
rajivmordani
 
Venkat Subramaniam Blending Java With Dynamic Languages
Venkat Subramaniam Blending Java With Dynamic LanguagesVenkat Subramaniam Blending Java With Dynamic Languages
Venkat Subramaniam Blending Java With Dynamic Languages
deimos
 
Using React with Grails 3
Using React with Grails 3Using React with Grails 3
Using React with Grails 3
Zachary Klein
 
Enabling White-Box Reuse in a Pure Composition Language
Enabling White-Box Reuse in a Pure Composition LanguageEnabling White-Box Reuse in a Pure Composition Language
Enabling White-Box Reuse in a Pure Composition Language
elliando dias
 
ArangoDB
ArangoDBArangoDB
企业级软件的组件化和动态化开发实践
企业级软件的组件化和动态化开发实践企业级软件的组件化和动态化开发实践
企业级软件的组件化和动态化开发实践
Jacky Chi
 
"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson
GWTcon
 
Language-Oriented Programming and Language Workbenches: Building Domain Langu...
Language-Oriented Programming and Language Workbenches: Building Domain Langu...Language-Oriented Programming and Language Workbenches: Building Domain Langu...
Language-Oriented Programming and Language Workbenches: Building Domain Langu...
elliando dias
 
Java 8 Overview
Java 8 OverviewJava 8 Overview
Java 8 Overview
Nicola Pedot
 
Launchpad: Lessons Learnt
Launchpad: Lessons LearntLaunchpad: Lessons Learnt
Launchpad: Lessons Learnt
Tim Penhey
 
Groovy And Grails Introduction
Groovy And Grails IntroductionGroovy And Grails Introduction
Groovy And Grails Introduction
Eric Weimer
 

Similar to Adapter Design Pattern (20)

Adapter Pattern Abhijit Hiremagalur 200603
Adapter Pattern Abhijit Hiremagalur 200603Adapter Pattern Abhijit Hiremagalur 200603
Adapter Pattern Abhijit Hiremagalur 200603
 
Creational Design Patterns
Creational Design PatternsCreational Design Patterns
Creational Design Patterns
 
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
 
jdays 2015
jdays 2015jdays 2015
jdays 2015
 
Anti Object-Oriented Design Patterns
Anti Object-Oriented Design PatternsAnti Object-Oriented Design Patterns
Anti Object-Oriented Design Patterns
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React Native
 
Visage Android Hands-on Lab (OSCON)
Visage Android Hands-on Lab (OSCON)Visage Android Hands-on Lab (OSCON)
Visage Android Hands-on Lab (OSCON)
 
Lecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Lecture 8 - Qooxdoo - Rap Course At The University Of SzegedLecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Lecture 8 - Qooxdoo - Rap Course At The University Of Szeged
 
Redux vs GraphQL
Redux vs GraphQLRedux vs GraphQL
Redux vs GraphQL
 
Laird Best Practices Ajax World West2008
Laird Best Practices Ajax World West2008Laird Best Practices Ajax World West2008
Laird Best Practices Ajax World West2008
 
Venkat Subramaniam Blending Java With Dynamic Languages
Venkat Subramaniam Blending Java With Dynamic LanguagesVenkat Subramaniam Blending Java With Dynamic Languages
Venkat Subramaniam Blending Java With Dynamic Languages
 
Using React with Grails 3
Using React with Grails 3Using React with Grails 3
Using React with Grails 3
 
Enabling White-Box Reuse in a Pure Composition Language
Enabling White-Box Reuse in a Pure Composition LanguageEnabling White-Box Reuse in a Pure Composition Language
Enabling White-Box Reuse in a Pure Composition Language
 
ArangoDB
ArangoDBArangoDB
ArangoDB
 
企业级软件的组件化和动态化开发实践
企业级软件的组件化和动态化开发实践企业级软件的组件化和动态化开发实践
企业级软件的组件化和动态化开发实践
 
"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson
 
Language-Oriented Programming and Language Workbenches: Building Domain Langu...
Language-Oriented Programming and Language Workbenches: Building Domain Langu...Language-Oriented Programming and Language Workbenches: Building Domain Langu...
Language-Oriented Programming and Language Workbenches: Building Domain Langu...
 
Java 8 Overview
Java 8 OverviewJava 8 Overview
Java 8 Overview
 
Launchpad: Lessons Learnt
Launchpad: Lessons LearntLaunchpad: Lessons Learnt
Launchpad: Lessons Learnt
 
Groovy And Grails Introduction
Groovy And Grails IntroductionGroovy And Grails Introduction
Groovy And Grails Introduction
 

More from guy_davis

Adopting Scrum and Agile
Adopting Scrum and AgileAdopting Scrum and Agile
Adopting Scrum and Agile
guy_davis
 
Pragmatic Programmer
Pragmatic ProgrammerPragmatic Programmer
Pragmatic Programmer
guy_davis
 
Content Caching with Rails
Content Caching with RailsContent Caching with Rails
Content Caching with Rails
guy_davis
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
guy_davis
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
guy_davis
 
Agile Software Development Methodologies
Agile Software Development MethodologiesAgile Software Development Methodologies
Agile Software Development Methodologies
guy_davis
 
Project Monitoring and Control
Project Monitoring and ControlProject Monitoring and Control
Project Monitoring and Control
guy_davis
 
The Human Side of Software Development
The Human Side of Software DevelopmentThe Human Side of Software Development
The Human Side of Software Development
guy_davis
 
Software Quality Plan
Software Quality PlanSoftware Quality Plan
Software Quality Plan
guy_davis
 
Unified Process
Unified ProcessUnified Process
Unified Process
guy_davis
 
Software Configuration Management
Software Configuration ManagementSoftware Configuration Management
Software Configuration Management
guy_davis
 
Quality Function Deployment
Quality Function DeploymentQuality Function Deployment
Quality Function Deployment
guy_davis
 

More from guy_davis (12)

Adopting Scrum and Agile
Adopting Scrum and AgileAdopting Scrum and Agile
Adopting Scrum and Agile
 
Pragmatic Programmer
Pragmatic ProgrammerPragmatic Programmer
Pragmatic Programmer
 
Content Caching with Rails
Content Caching with RailsContent Caching with Rails
Content Caching with Rails
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
 
Agile Software Development Methodologies
Agile Software Development MethodologiesAgile Software Development Methodologies
Agile Software Development Methodologies
 
Project Monitoring and Control
Project Monitoring and ControlProject Monitoring and Control
Project Monitoring and Control
 
The Human Side of Software Development
The Human Side of Software DevelopmentThe Human Side of Software Development
The Human Side of Software Development
 
Software Quality Plan
Software Quality PlanSoftware Quality Plan
Software Quality Plan
 
Unified Process
Unified ProcessUnified Process
Unified Process
 
Software Configuration Management
Software Configuration ManagementSoftware Configuration Management
Software Configuration Management
 
Quality Function Deployment
Quality Function DeploymentQuality Function Deployment
Quality Function Deployment
 

Recently uploaded

GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 

Recently uploaded (20)

GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 

Adapter Design Pattern

  • 1. Adapter SENG 609.04 Design Patterns Winter, 2003 Presented by Ming Zhou, Guy Davis
  • 2. Agenda Intent & Motivation  Structure  Applicability  Consequences  Known Uses  Related Patterns  References  - Total 17 pages - 1
  • 3. What is Adapter? Change the interface of a  class into another interface which is expected by the client. A.K.A. Wrapper  - Total 17 pages - 1
  • 4. What is Adapter? Change the interface of a  class into another interface which is expected by the client. A.K.A. Wrapper  - Total 17 pages - 1
  • 5. What is Adapter? Change the interface of a  class into another interface which is expected by the client. A.K.A. Wrapper  - Total 17 pages - 1
  • 6. Motivation - Total 17 pages - 1
  • 7. Motivation - Total 17 pages - 1
  • 8. Motivation - Total 17 pages - 1
  • 9. Motivation 1 1 - Total 17 pages - 1
  • 10. Structure (Class) - Total 17 pages - 1
  • 11. Structure (Object) - Total 17 pages - 1
  • 12. Applicability - Total 17 pages - 1
  • 13. Applicability Use an existing class whose interface  does not match the requirement - Total 17 pages - 1
  • 14. Applicability Use an existing class whose interface  does not match the requirement Create a reusable class though the  interfaces are not necessary compatible with callers - Total 17 pages - 1
  • 15. Applicability Use an existing class whose interface  does not match the requirement  Create a reusable class though the interfaces are not necessary compatible with callers  Want to use several existing subclasses, but it is impractical to subclass everyone. (Object Adapter Only) - Total 17 pages - 1
  • 16. Class Adapter Pattern Pros  Only 1 new object, no additional indirection  Less code required than the object Adapter  Can override Adaptee's behaviour as required  Cons  Requires sub-classing (tough for single  inheritance) Less flexible than object Adapter  - Total 17 pages - 1
  • 17. Object Adapter Pattern Pros  More flexible than class Adapter  Doesn't require sub-classing to work  Adapter works with Adaptee and all of its  subclasses Cons  Harder to override Adaptee behavior  Requires more code to implement  properly - Total 17 pages - 1
  • 18. Pluggable Adapters implemented with abstract operations  - Total 17 pages - 1
  • 19. Pluggable Adapters implemented with delegate objects  - Total 17 pages - 1
  • 20. Two-way Adapters class PegAdapter: public SquarePeg, class SquarePeg { RoundPeg { public: void virtual squarePegOperation() public: { blah } void virtual roundPegOperation() { } add some corners; squarePegOperation(); class RoundPeg { } public: void virtual squarePegOperation() { void virtual roundPegOperation() add some corners; { blah } roundPegOperation(); } } } - Total 17 pages - 1
  • 21. Adapting Local Classes to RMI Comparison:  Increases reusability of local class  Improves performance of local class  Doesn't use Java single parent by subclassing (uses composition) - Total 17 pages - 1
  • 22. Related Patterns Adapter can be similar to the remote  form of Proxy. However, Proxy doesn't change interfaces. Decorator enhances another object  without changing its interface. Bridge similar structure to Adapter,  but different intent. Separates interface from implementation. - Total 17 pages - 1
  • 23. Conclusions Allows collaboration between classes  with incompatible interfaces Implemented in either class-based  (inheritance) or object-based (composition & delegation) manner Useful pattern which promotes reuse  and allows integration of diverse software components - Total 17 pages - 1
  • 24. References Becker, Dan. Design networked applications in RMI using the Adapter design  pattern. JavaWorld Magazine, May 1999. http://www.javaworld.com/javaworld/ jw-05-1999/jw-05-networked.html Buschmann et al. A System of Patterns: Pattern-Oriented Software Architecture.  John Wiley and Sons. Chichester. 1996 Gamma et al. Design Patterns: Elements of Reusable Object-Oriented Software.  Addison-Wesley. Boston. 1995 Nguyen, D.X. Tutorial 10: Stacks and Queues: The Adapter Pattern. Rice  University. 1999. http://www.owlnet.rice.edu/~comp212/99-fall/tutorials/10/ tutorial10.html Whitney, Roger. CS 635 Advanced Object-Oriented Design & Programming. San  Diego State University. 2001. http://www.eli.sdsu.edu/courses/spring01/cs635/ notes/proxy/proxy.html#Heading10 Shalloway, Alan., and Trott, James R., Design Patterns Explained: A New  Perspective on Object-Oriented Design, Addison-Wesley, 2002. Rising, Linda., The Patterns Handbook: Techniques, Strategies, and Applications,  Cambridge university Press, 1998. - Total 17 pages - 1
  • 25. Questions? - Total 17 pages - 1
  • 26. Questions? - Total 17 pages - 1
  • 27. Java Native Interface (JNI) SENG 609.04 Design Patterns Winter, 2003 Presented by Guy Davis, Ming Zhou
  • 28. Agenda Overview  Justification  Hello World!  Summary  References  Q&A  - Total 17 pages - 1
  • 29. JNI Overview - Total 17 pages - 1
  • 30. Interactions with Native Code Access to Java world from native code Access to- native code from Java Total 17 pages - 1
  • 31. Justification Pros:  Reuse: allows access to useful native code  Efficiency: use best language for the task Cons:  Applets: doesn't work as they're mobile  Portability: native methods aren't portable  Extra work: javah, create shared native libs - Total 17 pages - 1
  • 32. HelloWorld.java class HelloWorld { public native void displayHelloWorld(); static { System.loadLibrary(quot;helloquot;); } public static void main(String[] args) { new HelloWorld().displayHelloWorld(); } } - Total 17 pages - 1
  • 33. HelloWorld.java class HelloWorld { public native void displayHelloWorld(); static { System.loadLibrary(quot;helloquot;); } public static void main(String[] args) { new HelloWorld().displayHelloWorld(); } } - Total 17 pages - 1
  • 34. HelloWorld.java class HelloWorld { public native void displayHelloWorld(); static { System.loadLibrary(quot;helloquot;); } public static void main(String[] args) { new HelloWorld().displayHelloWorld(); } } - Total 17 pages - 1
  • 35. HelloWorld.java class HelloWorld { public native void displayHelloWorld(); static { System.loadLibrary(quot;helloquot;); } public static void main(String[] args) { new HelloWorld().displayHelloWorld(); } } - Total 17 pages - 1
  • 36. HelloWorld.h #include “jni.h” /* Header for class HelloWorld */ #ifndef _Included_HelloWorld #define _Included_HelloWorld #ifdef __cplusplus extern “C” { #endif /* * Class: HelloWorld * Method: displayHelloWorld * Signature: ()V */ JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld(JNIEnv *, jobject); #ifdef __cplusplus } #endif #endif - Total 17 pages - 1
  • 37. HelloWorld.h #include “jni.h” /* Header for class HelloWorld */ #ifndef _Included_HelloWorld #define _Included_HelloWorld #ifdef __cplusplus extern “C” { #endif /* * Class: HelloWorld * Method: displayHelloWorld * Signature: ()V */ JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld(JNIEnv *, jobject); #ifdef __cplusplus } #endif #endif - Total 17 pages - 1
  • 38. HelloWorld.h #include “jni.h” /* Header for class HelloWorld */ #ifndef _Included_HelloWorld #define _Included_HelloWorld #ifdef __cplusplus extern “C” { #endif /* * Class: HelloWorld * Method: displayHelloWorld * Signature: ()V */ JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld(JNIEnv *, jobject); #ifdef __cplusplus } #endif #endif - Total 17 pages - 1
  • 39. HelloWorldImp.c #include <jni.h> #include quot;HelloWorld.hquot; #include <stdio.h> JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj) { printf(quot;Hello world!nquot;); return; } - Total 17 pages - 1
  • 40. HelloWorldImp.c #include <jni.h> #include quot;HelloWorld.hquot; #include <stdio.h> JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj) { printf(quot;Hello world!nquot;); return; } - Total 17 pages - 1
  • 41. HelloWorldImp.c #include <jni.h> #include quot;HelloWorld.hquot; #include <stdio.h> JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj) { printf(quot;Hello world!nquot;); return; } - Total 17 pages - 1
  • 42. HelloWorldImp.c #include <jni.h> #include quot;HelloWorld.hquot; #include <stdio.h> JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj) { printf(quot;Hello world!nquot;); return; } - Total 17 pages - 1
  • 43. Create a Shared Library class HelloWorld { ... System.loadLibrary(quot;helloquot;); ... } Compile the native code into a shared library: (example for MS Windows Visual C++ 4.0) cl -Ic:javainclude -Ic:javaincludewin32 -LD HelloWorldImp.c -Fehello.dll - Total 17 pages - 1
  • 44. Run the Program Command: java HelloWorld Result: Hello World! Possible
exceptions: java.lang.UnsatisfiedLinkError: no hello in shared library path at java.lang.Runtime.loadLibrary(Runtime.java) at java.lang.System.loadLibrary(System.java) at java.lang.Thread.init(Thread.java) - Total 17 pages - 1
  • 45. Summary Connect Java with native languages Code reuse Powerful Compromise of Java safety features,  cross-platform and dynamic ability JNI call is slow and costful  Not work well for applets  - Total 17 pages - 1
  • 46. References  Glenn L. Vanderburg. et al., Tricks of the Java Programming Gurus, 1996, http://docs.rinet.ru:8080/ JaTricks/  Beth Stearns, Trail: Java Native Interface, Sun Microsystems, Inc., 2003, http://java.sun.com/docs/ books/tutorial/native1.1/  Roedy Green, JNI, The Java Native Interface, Canadian Mind Products, 2002, http://mindprod.com/jni.html  Kong Wenyu, A Brief Introduction to Java Native Interface, http://www.geocities.com/kongwenyu/jni.html - Total 17 pages - 1
  • 47. Questions? - Total 17 pages - 1
  • 48. Questions? - Total 17 pages - 1

Editor's Notes

  1. Java Native Interface provides an means of interacting with native platform classes and functions through the creation of shared libraries. JNI can be used with most languages such as C, C++, Fortran, Cobol, etc...
  2. Full two-way interaction. Native code can interact with Java objects and their methods. Can also generate and throw exceptions that can be handled by Java code. Java code has full access to functionality contained with the native code through the generated interface definitions. Full passing of primitive parameters after conversion (strings to UTF)
  3. There is a ton of existing useful code in &#x201C;native&#x201D; languages: Numerical analysis libraries like LAPACK and BLAS in Fortran Lots of business logic contained with Cobol code Much high-speed code is written in C or assembly
  4. Keyword 'native' used to indicate methods that are available through shared libraries of native code.
  5. Loading the library: On Unix, looks for &#x201C;libhello.so&#x201D; or similar On Win, looks for &#x201C;hello.dll&#x201D; Show how to generate library later...
  6. Once library is loaded, can call native methods defined earlier. Finally, compile the class with: javac HelloWorld.java
  7. Autogenerated with call to: javah -jni HelloWorld
  8. Signature indicates no parameters being passed and void return clause.
  9. The JNIEXPORT and JNICALL macros are defined in jni_md.h which contains platform specific definitions. JNIENV is an interface pointer used to invoke JNI calls. jobject is the Java object on which the call is invoked.
  10. The JNIEXPORT and JNICALL macros are defined in jni_md.h which contains platform specific definitions. JNIENV is an interface pointer used to invoke JNI calls. jobject is the Java object on which the call is invoked.
  11. The JNIEXPORT and JNICALL macros are defined in jni_md.h which contains platform specific definitions. JNIENV is an interface pointer used to invoke JNI calls. jobject is the Java object on which the call is invoked.
  12. The JNIEXPORT and JNICALL macros are defined in jni_md.h which contains platform specific definitions. JNIENV is an interface pointer used to invoke JNI calls. jobject is the Java object on which the call is invoked.
  13. The JNIEXPORT and JNICALL macros are defined in jni_md.h which contains platform specific definitions. JNIENV is an interface pointer used to invoke JNI calls. jobject is the Java object on which the call is invoked.