Wrapper over server classes (similar to C typedef)
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Asawari_Joglekar
Posted On:   Tuesday, May 14, 2002 09:57 AM

p>Hi, I'm new to Java and I have a problem about some basic stuff. I have a library that contains all the classes with names starting with "XX" like, XXObject, XXFoo, XXBar etc... I can not change names of these. The client for this library uses class names starting with YY, like YYObject, YYFoo, YYBar etc. Interface of XX* and YY* match exactly. But I am not allowed to change code from client or library containing XX* objects. What I need to do is to write a wrapper so that client can talk to library. Parts of client code looks like this : YYFoo = new YYFoo(); // creating new String s = YYFoo.g   More>>

p>Hi,

I'm new to Java and I have a problem about some basic stuff.

I have a library that contains all the classes with names starting with "XX" like,
XXObject, XXFoo, XXBar etc... I can not change names of these.

The client for this library uses class names starting with YY, like
YYObject, YYFoo, YYBar etc.

Interface of XX* and YY* match exactly. But I am not allowed to change code from client or library containing XX* objects.

What I need to do is to write a wrapper so that client can talk to library.

Parts of client code looks like this :

YYFoo = new YYFoo(); // creating new

String s = YYFoo.getStaticString(); // calling static function
Y

YBar bar = yyfoo.doSomething(yyStuff, someString,yySomething); // yyfoo is object of type YYFoo, yyStuff is object of type YYStuff and yySomething is object of type YYSomething


I assume my wrapper would contain all YY* classes which would forward each public function call to proper XX* functions.

In C/C++ this was achievable by writing a header file containing lines

typedef XXObject YYObject;

typedef XXFoo YYFoo; ...

But how to do it in Java with little effort (that can be automated using scripting)

Thanx for the help

AJ

   <<Less

Re: Wrapper over server classes (similar to C typedef)

Posted By:   Steve_Long  
Posted On:   Monday, May 20, 2002 04:54 AM

if the classes are not declared as final, you could create a tranlation layer for each of the XX* classes using extends, ie


class YYFoo extends XXFoo {}


class YYBar extends XXBar {}

this approach in effect aliases all XX* classes as YY* classes. if any of the XX* classes are declared as final, then you have more work to do. you actually have to create a wrapper for each attribute and method in an XX class in a YY class, ie


import XXFoo;



class YYFoo {



XXFoo.XXFooVar1 YYFooVar1 = new XXFoo.XXFooVar1();


XXFoo.XXFooVar2 YYFooVar2 = new XXFoo.XXFooVar2();



fooOp1 () {


XXFoo.fooOp1();


}



fooOp2 () {


XXFoo.fooOp2();


}


}

Re: Wrapper over server classes (similar to C typedef)

Posted By:   Mike_Friedrich  
Posted On:   Saturday, May 18, 2002 01:28 AM

But why you can't simply use the XX* classes? For usage you must not change those classes.


Use import or the full qualified names and add this library (jar) to your classpath.


Using a typedef in C++ is nothing else than an alias, you can use the "old" and "new" name in C++ without any difference. If you have name-conflicts in java, use the full qualified names (means with package-info like java.lang.Object instead of Object).


If you mean something else, please make it clearer for me.

Regards, Mike

Re: Wrapper over server classes (similar to C typedef)

Posted By:   Sebastien_Meric  
Posted On:   Tuesday, May 14, 2002 11:26 PM

Nothing link typedef in c++ exists in java. Thus you'll have to make more efforts to get this running.

You may use reflexion to achieve this in java.lang.reflect

Regards
About | Sitemap | Contact