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
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.