Originally posted by Maria Lepschy:
Hello ranchers,
I am thinking about the design and some things are not clear for me.
I have no much experience with Java and design patterns, so I need your help.
1. I have seen that many people have implemented an adapter class to the Data class to have all methods defined in the Sun interface DB but throwing the IOException. Is this really necessary? I have a try catch block in the methods, is this not Ok? Why is important to have the exception in the throw clause for the methods?
2.For the local mode I don't need to care about locking, synchonization. So I think I have to create a DataLocal class implementing also the DB interface like the Data class or a adapter class.
I wait for your response.
Regards,
Maria
Hi Maria, for the second point, what if the CSR opens a couple of windows and work with them. Don't you want to do locking at that time? I'm not sure about it, but its a scenario to take into consideration right?
You may assume that at any moment, at most one program is accessing the database file.
Originally posted by Maria Lepschy:
1. I have seen that many people have implemented an adapter class to the Data class to have all methods defined in the Sun interface DB but throwing the IOException. Is this really necessary? I have a try catch block in the methods, is this not Ok? Why is important to have the exception in the throw clause for the methods?
If your network communications approach uses RMI you will need an interface whose methods throw RemoteException (or a superclass thereof). This is the reason people are interested in having a common interface (suitable for local or remote access) whose methods are declared to throw IOException (a superclass of RemoteException). RMI requires an interface (the remote interface) that extends both this common interface and the Remote inteface. The class implementing this remote interface extends UnicastRemoteObject which gives the class the ability to be accessed remotely via RMI. The remote method invocation compiler (rmic) is run against the class implementing the remote interface to produce a stub for that class. One of the things the rmic does is check that all the methods in the class implementing the remote interface are declared to throw RemoteException. This is because when RMI is involved it is always possible that there will be communications problems that may arise and these problems will trigger RemoteExceptions. RMI requires that the remote interface implementing class handle these RemoteExceptions and the rmic enforces this requirement. These interfaces and classes (including the stub class) are all needed to support an RMI solution.
2.For the local mode I don't need to care about locking, synchonization. So I think I have to create a DataLocal class implementing also the DB interface like the Data class or a adapter class.
While it's true that you don't need to care about locking and synchronization for local mode, you might find that the burdens of locking and synchronization are not too onerous for the local database situation, in which case Data itself can server as the DataLocal class.
Regards, George
SCJP, SCJD, SCWCD, SCBCD
Originally posted by Maria Lepschy:
If I understand you correctly (my english is not the best) you wrote that
it doesn't matter if I provide the locking functionality also for local database access? Maybe it is better to not implement too many classes if there are not really needed.
Regards, George
SCJP, SCJD, SCWCD, SCBCD
Can you smell this for me? I think this tiny ad smells like blueberry pie!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|