Jump to content

Do I need to check the arguments of a public function if I test the input before


HGeneAnthony

Recommended Posts

I don't know if this is even an issue, but I was wondering with a public function of a class, do I need to test the arguments to see whether the data is valid even if I test the data before I pass it to the function? 

 

For example, I have a class to manage the users in my system.  The class is responsible for checking the input it's passed to make sure it's allowed, only after it's done will it send the data to my seperate database class which handles the database details.  The database class is set up with public functions so it can receive the data from the user manager class.  Nothing else is set up to touch the database class.  Do I still need to check the data?  Can someone somehow access the database classes public functions in ways I hadn't planned for?  I can't think how they would but I'd like to know if this is something I should worry about because I'd like to put a lot of the logic in the user manager class and keep the database class simple.  Also this system makes it much easier to use mock objects which I can't do nearly as well otherwise.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.