Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Methods with External Code (Java)

Tags:

java

methods

I am currently working on a Java graphics API and want to enable easy customization. Part of what I have in mind is being able to replace standard code with custom code. To achieve this, I'm wondering if I can have the methods of my code reference code in external, swappable files (that may or may not be written in a different language, such as RhinoScript). For example, if someone using the API feels the code of a particular method is inefficient, they could replace the file that method references with their own file with code which they feel is more efficient.

I understand interfaces and abstract classes may be an option to achieve this, but I feel the approach I described, if achievable, would have the advantage of reusable code, easier implementations of the API using different scripting languages, and a generally easier way to modify code.

The bottom line of what I'm asking is this: is it possible to have a method execute code contained in a stand alone file (contains only the code the method would execute), which may or may not be written in a language separate from Java, and if so, how would I go about doing this or what subjects should I research for this?

In closing, I apologize if this is not an acceptable question to ask on this forum or I have not stated my question clearly enough.

like image 345
Dizzy Avatar asked Jun 13 '26 16:06

Dizzy


1 Answers

I think this is not the way to go, if you want to offer customization to your library, interfaces and abstract classes are your best bet. Implementing wrappers for other languages will be very inefficient and probably relatively slow, not even starting with the complexity it add to your code. How are you going to pass arguments? Receive return values? Manage exceptions in case of run-time or syntax errors?

Of course it all possible, but as a developer, I would never use an API that works like you described.

like image 183
Wesley Avatar answered Jun 16 '26 06:06

Wesley