65.9K
CodeProject is changing. Read more.
Home

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

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Oct 17, 2011

CPOL

1 min read

viewsIcon

16169

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.

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.

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.