• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

operating mode--share code

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
operating mode--share code
In a networked mode and a non-networked mode, how to share most of
the code? I am thinking this question but have not got a good solution
yet.
I thought that let both class Data and class rmi_Impl implement the
interface DBAccess(the Sun's interface). Because methods in interface
DBAccess do not throw Remote Exceptions and we MUST NOT chang it,
this approach doesn't work.
Anyone has a good idea and give me some suggestions?
Peter
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Peter,
Think about having an Adapter/Wrapper class that calls the methods in the
Data class. The adapter class should also implement an interface.
This adapter class can be used both in local and remote mode. How do you use the class in remote mode? Well then create a class for remote mode that implements the adapter class interface and is also given a handle to
the non remote adapter upon creation. Now the remote class has to implement all of the methods in the interface, but the body of each method is simply a call to the non remote class.
Ex. In this example DBAdapter is the interface that Adapters implements.
The following is what some of the methods would look like in the remote
Adapter

Remember though you have to make sure the adapter interface, DBAdapter, is remote capable for the remote adapter. To do this you must declare the
interface as throwing an IOException for every method.
This is just one design I have seen many times.
 
Peter Yunguang Qiu
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Bill:
Happy New Year to you!
Thank you very much for your detailed explanation.
 
reply
    Bookmark Topic Watch Topic
  • New Topic