File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Subclassing Vs Extending Data 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 "Subclassing Vs Extending Data" Watch "Subclassing Vs Extending Data" New topic
Author

Subclassing Vs Extending Data

Aaron Dressin
Greenhorn

Joined: May 10, 2002
Posts: 29
Hi. I am almost ready to submit my assignment, but while writing my design document I ran into an issue that may cost me some points, and I am hoping to bounce it off of some of you for your opinions.
My instructions state that I may enhance the Data class by, "...modification or subclassing...". Here is what I did, you tell me if this does not meet the criteria:
1. I "abstracted" all of the methods of the Data class into an interface (DataInterface).
2. I modified the provided Data class to implement DataInterface and I implemented the criteriaFind() method in this class. I then use this class for my "client-side" Data... that is, the Data that is used for the client in non-network mode. In this class, the lock() and unlock() methods are empty implementations.
3. I created my "server-side" Data class by extending UnicastRemoteObject (used as the ClientConnection that is returned to the remote client). Here is the catch: I WRAPPED the provided Data class here and simply pass all method calls directly through EXCEPT for the lock() and unlock() calls... in which case, I use the record lock manager and so on.
I hope that this makes sense... if not, I can explain better.
Does this sound like a violation of the rules? Technically, I did not EXTEND the Data class to implement the lock() and unlock() methods, but I wrapped them. Looking back now, the only other way I can see to do it is to write another class the extends Data, implement the lock(), unlock() here and pass all calls from the ClientConnection to it... but that seems like a waste of code.
What do you think? Any suggestions are much appreciated.
Regards,
Aaron
[ November 18, 2002: Message edited by: Aaron Dressin ]
[ November 18, 2002: Message edited by: Aaron Dressin ]

-Aaron
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
This sounds very much like the way I did it, and I got full marks on this part of the assignment. Don't worry. This is entirely within the rules.
One small enhancement you might like to consider is, in ClientConnection, enforce the acquisition of locks in the methods that write to the database. Just because it's a good idea -- not because it would get you any more points.
- Peter
Aaron Dressin
Greenhorn

Joined: May 10, 2002
Posts: 29
Thanks Peter... I'm not sure I understand you recommendation however. I enforce the locks in the "bookFlight()" method within a client-side facade (that has no knowledge about which "Data" it is using... remote or local). If I was to put the locking code within the ClientConnection class, then the locking would be at the atomic level of a method call, rather than a set of calls (like "bookFlight()").
Can you please elaborate? I appreciate your feedback.
Regards,
Aaron
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Ok. But before I start: this is not essential. I doubt if it will impact your score.
Data is a completely generic database, and the instructions (at least the ones I had two years ago) stress re-use. So the network layer I added was completely generic too. The issue now is, as the writer of this generic multi-user database, do I trust the developers writing code against this database?
Hey, I'm a developer myself. I know first hand that developers are not to be trusted.
So I figured that if client A had a lock on record X, then client B should not be able to modify record X even if B never bothered to acquire a lock the way it ought to. The way I personally handled it was, in cases where a client would try to update or delete a record without lock, to have ClientConnection acquire a lock, perform the update/delete, then release the lock again. This added only a few lines of code and a much higher degree of confidence in my data integrity.
- Peter
Jeff Shen
Ranch Hand

Joined: Sep 04, 2002
Posts: 31
One thing I am not sure, if your server side Data class does not implement DataInterface, how do you deal with data on the client side uniquely?
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
I think Data would implement DataInterface?
- Peter
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Peter,
to have ClientConnection acquire a lock, perform the update/delete, then release the lock again. This added only a few lines of code and a much higher degree of confidence in my data integrity.

It's this quote that finally converted me to using a ClientConnection to enforce the acquire/update/release protocol.It's much easier to ignore Threads from this viewpoint than nearer to the data .Though the other way is not wrong,obviously as assessors don't penalise.
Am I right in saying that in here could also enforce rolling back transactional failures and Exception handling ?
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Anyone has an answer?
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
I am not sure what you mean. Data does not support transactions (but that isn't what you mean, right?) and I'm not sure how you would handle exceptions at that point?
- Peter
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Peter, I didn't want to hijack Aaron's thread so started a new one "Can ClientConnection handle transaction,exception handling"
Thanks
 
Don't get me started about those stupid light bulbs.
 
subject: Subclassing Vs Extending Data