in my exam,i need implent these interface: public void update(int recNo, String data, long lockCookie) public int create(String data) do i need check the parameter String data to ensure is legal? thanks!
[edited title to reduce volume! -BG] [ April 29, 2006: Message edited by: Barry Gaunt ]
In some methods I do just to show I can (mainly in the constructor of my wrapper class), in most I don't. For that I use assertions, as such errors should only happen during application testing and never during deployment (if they do happen after deployment it means there has been no testing, not my problem).
When you get the wrong number of elements in the array, it's a programmer error by definition, which you would want to give a nasty error so the person making the error will fix it.
Unless you are following Bertrand Meyer's Design By Contract concept you should certainly do a sanity check on your input parameters. Make sure refrences are not null, record numbers are not negative. Lock cookies would be checked at a later stage.
If you are following design by contract, the caller would have checked them.
Eventually of course there's a check, way down in the method that creates the actual write buffer for example:
The find method will work just fine if the number of fields passed doesn't match the number of fields in the record. If less, the rest of the record is not matched, if more the rest of the arguments are ignored.
I was under the impression that the question related to the user interface rather than the backend. I take some liberty there because it's more or less a single logical unit. Checks there I do only on the boundaries where someone could plug in enhancements (like a new search dialog) and classes designed for reuse in other clients.
Joined: Mar 26, 2006
thanks everybody! in my requirement "Portions of your submission will be analyzed by software....." so i'm afraid that the interface may be tested under all circumstances! for example,some field must be number;some field must be "Y" or "N";and how should i deal with this condition! BTW:the interface can't be change so throws a new checked Exception is not allowed! the last way is throwing a RuntimeException,but it's crazy for validate a input parameter! thanks [ May 01, 2006: Message edited by: LianGuang Wang ]
I was wondering if it makes sense to validate parameters in the Table (or TableModel) itself. Since Table comes with editors, some sanity checks can be automatically taken care of.(Sun wants JTable!) It Table OK's the data, it makes to the database, no more checks.
Jeroen T Wenting
Joined: Apr 21, 2006
Depends on how you use your JTable. In my implementation it's strictly for displaying data only, I've disabled all editing functions (while adding other things to make it look nice, like colour coding of records with different status).