Yikes. Can you justify that last point? Personally, I've come to loathe APIs that throw a completely amorphous Exception at you. You can make a case for throwing IOException, but Exception...?Originally posted by Michael Tu:
1. public interface DataInterface: All basic database operations are defined here, including criteriaFind, lock and unlock. Generic Exception is thrown in all methods.
Please revisit your Singleton assumption; it strikes me as a serious architectural mistake. Apart from the FBN assignment, how many database-driven applications do you know that use exactly one database table? In general, Singleton is the most abused design pattern around. Never use it unless there is a solid, fundamental reason why you can have only one instance of a class. The fact that you happen to need just one in a particular application is neither solid nor fundamental.4. public class LockManager: LockManager is implemented as Singleton. It keeps a reference to Data.
Why bother? Just have6. public interface RemoteDataInterface extends DataInterface, Remote: Basic database methods are exported here again. DatabaseException and RemoteException are thrown for all methods.
Junk this class, or turn it into a factory. It certainly shouldn't implement DataInterface. All you need is a place to instantiate a DataInterface object that is either Data, or a RemoteData stub. The rest of the application can take this object and work with that without worrying whether it's a local or remote implementation.10. public class ClientData: This is a wrapper class for local or remote database services. It automatically connects to local or remote database based on the database address argument upon instantiation. Again, all basic database operations are implemented.
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
You can make a case for throwing IOException, but Exception...?
Apart from the FBN assignment, how many database-driven applications do you know that use exactly one database table? In general, Singleton is the most abused design pattern around. Never use it unless there is a solid, fundamental reason why you can have only one instance of a class.
Why bother? Just have
code:
interface RemoteDataInterfaceextends DataInterface, Remote { // that's all folks}
All you need is a place to instantiate a DataInterface object that is either Data, or a RemoteData stub.
Laziness of the right kind is usually a good attribute in designers and coders. This is not the right kind. I can say a few things about this.Originally posted by Michael Tu:
[...] If you list all of them, the method definitions will be quite long, which I also don't like. A generic one looks more concise.
Your instructions probably told you to code for reuse. The Data class corresponds to a single, local database table. Now you've built a perfectly generic database server, but your architecture restricts it to a single LockManager, and therefore to a single Data instance. Which immediately makes it unusable to the 99.9% of the applications out there that actually need to have more than one database table. You've just ruined your reusability. If the gains in simplicity were huge, it'd be justifiable perhaps, but they aren't.[...] I don't quite understand what you mean by mentioning 'one database table'? [...]
Does this class need to be aware of anything other than the locked record numbers and their respective clients?The LockManager keeps a reference to Data for some basic database info, such as total record count.
If you don't need to narrow exceptions, the RemoteDataInterface is fully defined by the two interfaces it extends.No need to export methods here? I may have a try.
So where does the ClientData wrapper class come in?This is what I do.
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Does this class need to be aware of anything other than the locked record numbers and their respective clients?
So where does the ClientData wrapper class come in?
This implementation should include a class that implements the same public methods as the suncertify.db.Data class, although it will need different constructors to allow it to support the network configuration.
Sounds good. Not all of them need to throw DatabaseException.Originally posted by Michael Tu:
1) Change the method signatures in DataInterface to throw IOException and DatabaseException.
Looks good to me.2) Not implement the LockManager as Singleton.[...]
That's not a reason to put it in your design -- it doesn't really do anything, and for that reason alone it should be junked. If that meant you'd have to ignore the requirement, that is what you should do, carefully documenting the reasons why. But as it happens, you're satisfying the requirement without this class! You see, it says "should include". It doesn't say that you have to be the one writing it. The stub for RemoteData generated by rmic satisfies the requirement on all counts.The ClientData class is implemented merely for this requirement: This implementation should include a class that implements the same public methods as the suncertify.db.Data class[...]
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
You see, it says "should include". It doesn't say that you have to be the one writing it. The stub for RemoteData generated by rmic satisfies the requirement on all counts.
Personally, I've come to regard code as a necessary evil. Every single line of code that does not serve a very good purpose is harmful.Originally posted by Michael Tu:
Having such a class will do no harm though it is not necessary.
Let me reassure you. Based on what I've seen in this forum, both as a humble participant and as a moderator, the assessors will let you pass almost regardless of what you do provided that you have thought it through and document your reasons why.When I implement sth, I am always bugged by this question : does the assessor accept this approach?
All RemoteData instances are produced by a single factory. All share a single Data and a single LockManager.[...] Now I find it not very good as LockManager is solely used by RemoteData but declared outside of it. [...]
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Originally posted by Peter den Haan:
Why bother? Just have
"When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon. You just have to outrun the halfling."
They must already throw RemoteException (or its superclass, IOException) in DataInterface itself.Originally posted by Eddie Sheffield:
[QBDon't you have to explicitly rename all the methods and explicitly throw RemoteException?[/QB]
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Assuming you are using RMI, the answer is simple IMHO. Stay connected. RMI has been designed to abstract remote access to long-lived objects. Leave it up to the RMI implementation to optimise this process and to manage network connections as necessary. This is exactly the kind of low-level stuff that RMI is abstracting away from you, that you shouldn't have to bother about.Originally posted by Michael Tu:
1) A client may stay connected throughout or may work in cyclic mode of connection-transaction-close. Both have drawbacks.
That one of the design decisions you will have to make, isn't it? You can argue either way.2) For local mode, is it really not necessary to implement lock/unlock?
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
HTMLEditorKit to display it (read-only) in an application window
Hang a left on main. Then read this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|