Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DataClient problem

 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm stuck on the DataClient part. My DataClient implements all the public methods of Data by simply calling the method in the class (DataRemote or Data) for local or remote.
The problem is, they work fine in each case, but I can't combine them!
For example:
I declared a private class variable called
DataRemote db (remote) or Data db (local)
In the constructor:
I'll instantiates it to the DataRemote for Remote, Data for local
My other public methods are like this:
public void xxxxx(String cccc){
db.xxxxx(cccc);
}
The problem is, since they are two different classes, I cann't combine them. And it's driving me crazy rite now!!!
Any help is appreciated!!!
 
vin miller
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use an interface. If they both implement the same interface, you can reference either one of them by the interface type.
Data implements DBInterface
DataRemote implements DBInterface
DBInterface db = new Data()
or
DBInterface db = new DataRemote()
db.xxx()
 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks vin:
That was my original solution, but the problem is that my DataRemote extends DataGeneric (DBInterface), that means DataGeneric class must throw RemoteException.
If Data class implements DataGeneric, why not make Data implements DataRemote directly?
Another one of problem is that, all my DataClient's methods throws RemoteException, regardless which mode is in. This happens because I just have one version of DataClient that must satisfy both mode. Is this OK?
Sorry if I'm being a pain in the ass here!
 
Ihor Strutynskyj
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use an adaptor class to wrap calls and to catch and rethrow
exceptions of the type you need.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic