let's have set of classes want extend because have different properties i'll use in callback function (to come):
class extendme1 // class extendme2 // and wanted write new class extended programmatically. there way of doing this:
extendertemplate( <extendme1>, // class extend <aclasstoextendwith>, // new class name i'm extending callbackfunction() // function can run locally inside our new class ); let's method extendertemplate looked this:
void extendertemplate( <ext>, <newclass> ) { createclass( <newclass ).extends( <ext> ).run( callbackfunction ); } is there way of doing in java?
the resulting class programmatically built this:
public class aclasstoextendwith extends extendme1 { public aclasstoextendwith() { callbackfunction(); } public void callbackfunction() { // accesses belongs extendme1 } } context
we have set of ui controls have extend our own class, routine crap inside it, extend ui control (hopefully can done callback function). great if pack template method in end have these 3 paramaters.. ui control extending, want class called (so can call within our view) , change ui control (the callback function)
further clarification of how our team might use function
- so want extend ui control else has made.. know called..
- i need call somehow in code need give nice new name... need because want write more functionality it.
- i want modify ui control uses functionality instead.
i might end calling (this have pseudo)
extendertemplate( "newuicontrol", "uicontrol_table", { uicontrolrender.text = "new stuff added accessing extended method"; }); otherwise have this:
public class newuicontrol extends uicontrol_table { public void functionthatisrunbyframeworkautomatically() { // routine stuff accesses uicontrol_table , makes copies of , // modify , new stuff want in uicontrol // more routine stuff belongs accesses uicontrol_table , makes copies of , passes in modified stuff instead of typical stuff ui control outputs } }
i think, proxy looking for. sample code proxy documentation:
to create proxy interface foo:
invocationhandler handler = new myinvocationhandler(...); class proxyclass = proxy.getproxyclass( foo.class.getclassloader(), new class[] { foo.class }); foo f = (foo) proxyclass. getconstructor(new class[] { invocationhandler.class }). newinstance(new object[] { handler }); or more simply:
foo f = (foo) proxy.newproxyinstance(foo.class.getclassloader(), new class[] { foo.class }, handler); update:
i saw, proxy class proxies interfaces, not seem able extend classes.
Comments
Post a Comment