aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Data Client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Data Client" Watch "Data Client" New topic
Author

Data Client

Gosling Gong
Ranch Hand

Joined: Jun 20, 2002
Posts: 51
Please comment following design,
suncertify.db package
1. I have a DataInterface which declare all the public methods of Data
2. Modify Data class to impelment DataInterface
3. RemoteInterface extends Remote, DataInterface
4. RemoteData implements RemoteInterface
Now I can use a factory method to get DataInterface according to Local mode or remote mode.
What I am wondering is, do I need another DataClient which have all the public methods of Data and delegate all the call to the Data? I saw someone did so, they have a LocalData implements DataInterface.
I am realy confused why we should provide another local implementation for Data though we can use Data only if we make it implements DataInterface.
Thanks for help
ravindra janapreddy
Ranch Hand

Joined: Jan 30, 2001
Posts: 84
For local implementatiom, You don't need LocalDataClient, You can use Data class.


SCEA, SCBCD, SCWCD, SCJD, SCJP
Gosling Gong
Ranch Hand

Joined: Jun 20, 2002
Posts: 51
but in Sun's requirement, that, in our client implementation, there should be one class provides all the public class
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
Originally posted by Gosling Gong:
do I need another DataClient which have all the public methods of Data and delegate all the call to the Data?

Yes. You can call it a DataProxy and have it implement the DataInterface. In your design, how about DataInterface extending Remote and all the methods in it throw RemoteException and other exceptions if you like.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

Well I had a DataAccessLocal. I did not change the Data class. I would not change a class to add an implements or extends. If you want to do this then you should subclass the Data Class.
So therefore I had to have a DataAccessLocal implement my DataAccess interface. Because my Facade required a DataAccess class, so therefore I couldn't send it Data since it wasn't. I also had the interface, so that there was no locking in local mode. the lock and unlock method of my DataAccessLocal class was empty.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Robin Underwood
Ranch Hand

Joined: May 01, 2002
Posts: 117
Mark, please explain further why having Data implement DataInterface is bad. I did this to avoid having a local data wrapper only to provide a DataInterface for the Data class. My thinking is that the DataInterface cannot be used for another type of database (since it depends upon DataInfo and FieldInfo) and that Data and DataInterface would always be kept in sync. DataInterface is Data's public interface. Does this logic hold up?
Thanks again,
Robin
Gosling Gong
Ranch Hand

Joined: Jun 20, 2002
Posts: 51
Originally posted by Mark Spritzler:
Well I had a DataAccessLocal. I did not change the Data class. I would not change a class to add an implements or extends. If you want to do this then you should subclass the Data Class.
So therefore I had to have a DataAccessLocal implement my DataAccess interface. Because my Facade required a DataAccess class, so therefore I couldn't send it Data since it wasn't. I also had the interface, so that there was no locking in local mode. the lock and unlock method of my DataAccessLocal class was empty.
Mark


Thanks for your reply, Mark!
Just as Robin said, I change the Data to implements DataInterface only to reduce the wrapper class(proxy) of Data.
off course, you need DataAccessLocal implements DataAccess if your Data not implements DataAccess, but that is what I am wondering, why did you do so rather than did as i said which can reduce one proxy class?
As to Lock, I can leave them empty in Data, because local mode doesn't have lock, and let RemoteData to handle lock.
By the way, where do you think those DataAccess classes should locate? I think, since they are belong to Database accessing, so they should locate at suncertify.db package. base on that, we can say, suncertify.db package provide user a database with network function. what do you think?
thanks!
Gosling Gong
Ranch Hand

Joined: Jun 20, 2002
Posts: 51
Originally posted by Sai Prasad:

Yes. You can call it a DataProxy and have it implement the DataInterface. In your design, how about DataInterface extending Remote and all the methods in it throw RemoteException and other exceptions if you like.

thanks, Sai!
My DataInterface didn't extend Remote, but it does also throw RemoteException, and RemoteInterface throws RemoteException without no new methods declared.
I am still thinking about how to handle those Exceptions, should I throw all the Exceptions untill in Client Gui level?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

Yes, I put them in the db package. I had a Facade class, this facade class takes a DataAccess class as in it's constructor. I really did not want to change the Data class at all. I think there is a big OOP trap in going back to a class that already exists and has been proven to work, and changing some implementation like implementing an interface. While in this current spec, I could not forsee any problems down the road, however, at any time I could forsee this becoming a problem, or a chance of one.
I also wanted to make a DataAccess class have an instance of Data, rather than it actually being the Data class. I wanted this seperate.
Robin your logic is fine, again to me there are some principles and rules I follow in OOP, thinking that they will keep me out of trouble. One is changing the extends or implements portion of an already created class.
I also think that by having Local and Remote act the same way as having a DataAccess class which holds a reference to Data is easier for a junior programmer. It is symetrical too.
Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Data Client