Performing runtime implementation of a class methods : how ?
Hi everyone :
I have some classes for which I need to define their method's implementation at init time in my application.
The code of these methods is loaded from a database, so... this is sort of a runtime implementation of such methods. It is possible to do this ?
Thanxs for any help in advance,
Diego
> Hi everyone :
> I have some classes for which I need to define their
> method's implementation at init time in my
> application.
>
> The code of these methods is loaded from a database,
> so... this is sort of a runtime implementation of such
> methods. It is possible to do this ?
>
As described that is not possible. A 'class' is the lowest common denominator in java. There is no way to load just a method.
You could write an interface and then implement that interface. Then load those. And those would be called by your existing class. Each interface would describe one type of method, or several.
If you are familar with design patterns the "Strategy" pattern describes this (the idea not the implementation.)
I think I wasn't very clear. In fact, what I'd like to know is if there is in java any sort of script engine that could be started in my application as a thread and to which I would pass script code that would be interpreted and executed at runtime.Any idea ?
Thanxs for your explanations.
I understand what you say and I had already figured out the interface solution by I found out it couldn't work for this particular issue since, what I'd like to do is 'automatic' implementation of procedures.
I need to have a generic application that allows skilled users with programming knowledge to program their own implementation of several tasks that my application is going to perform for them.
So I thought that there could be a sort of script engine that would allow me to do this. I've heard of something like this in VisualBasic. There is a VBScript engine component that is called by a VB application and performs VSScripts loaded at runtime.
I was wondering if I could find something like this in Java.
http://www.beanshell.org/
http://www.judoscript.com/index.html
But you can also do as I did some time ago, where I didn't know about those java "true" scripting implementations.
I implemented a "pseudo-scripting" engine (I also wrote an article about it - in Italian, sorry), using dynamic compilation through sun.tools.javac API.
It was not so difficult, and you can see a web-based online demo on http://www.informaction.com/plotter/
Hope it helps...