• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

about parameter check

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
LianGuang Wang
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

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.

Thanks
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic