Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / All-Topics

Multi-Language Programming: Accessing Interface Objects Defined In Other Language_4

0.00/5 (No votes)
17 Oct 2011CPOL1 min read 16.1K  
Accessing interface objects defined in another language

A common object environment provides run-time support. Based on support of the environment, applications can access interface objects defined in other language. There are two methods, and we will look at them one by one in detail.

In the first method, the application can find an interface object defined in another language using a function of the environment. And then, it can access the object’s attributes or call the object’s functions. Interface objects may be identified by its UUID or name. The object’s name should be used carefully because there may be multiple objects with the same name.

Image 1

In the second method, for an environment supporting object-oriented programming, the application can create an instance of the entity class object of another language as we talked about previously. The instance can be accessed by the two languages simultaneously. This method is more flexible. The application can create overloading functions of class objects to support callback. For example, if an object with function “Add” is defined in Python language, an application in Java can create an instance of it and overload the function “Add”. Then, Python can callback to Java through the “Add” function.

Image 2

In the above figure, the Python class object defines two functions Add and Dec. The Add function is overridden by the Java instance. The instance is managed by the environment, and is visible to Java and Python. Python can call the Add function of the Java instance to perform the callback function. For the Dec function, because the instance does not override this function, the call will be redirected to the class object of Python.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)