Jump to content

Archived

This topic is now archived and is closed to further replies.

rubenski

[OOP] Three tier system - Where to check form input?

Recommended Posts

Hi folks. I am creating a three tiered system with a HTML front end and a mysql DB. I want to create a simple application that will store and retrieve information about rooms that are for rent (area, location, description, price_per_month, etc).

So far I have implemented

- a simple data class that connects with MYSQL and fires insert and update queries. (class RoomData)
- a business logic class that manages room fields (class Room)
- a HTML view containing a form that allows the user to enter a new room into the database.

[img]http://www.tekstenuitleg.net/class_schema.gif[/img]

Now, what happens when someone presses the submit bitton on the form? Obviously, the application must validate the form data first. This is where I get stuck, OO design-wise.

Where should I put the form validation code? In the Room class? Or would it be wiser to create a separate input validation class that extends Room?

What is your design strategy for input validation?


Share this post


Link to post
Share on other sites
while i can't comment on where to put your validation within the objects, i'll tell you how i do mine.  i use this approach in a non-OO way, but i think the process lends itself well to its own class.

i have a set of functions to validate various input types (email, phone, username, password, required (ie. not empty), etc.).  when i get my data, i run the functions as necessary and store all results within an array.  each function returns either 0 (int) or an error message, so when i check for errors i simply run a difference against 0 to pull out all the error strings.  if the resulting array is empty, then there were no errors, but otherwise i return the errors and exit the overall function.  this gives me a standardized validation method, albeit non-OO.

as i said earlier, i'll guess that a validation class is in order.  you'll be running input validation fairly integrally in any application, and so it's probably easiest to have it bundled together and just extend any overall application class with it.

maybe i'm wrong here, as i don't know the technicals ins and outs of good OO design.  just seems the most logical.

Share this post


Link to post
Share on other sites
[quote author=akitchin link=topic=104035.msg414786#msg414786 date=1155430169]
as i said earlier, i'll guess that a validation class is in order.  you'll be running input validation fairly integrally in any application, and so it's probably easiest to have it bundled together and just extend any overall application class with it.
[/quote]

This is basically what I thought too. However, when I think of it again, it doesn't seem right. If I create other classes like ehhhm.... 'Member', 'Appointment', etc I'd have to create a separate Validator class to extend each of them. These separate validator classes would all contain nearly the same code. It sounds logical to me to create a separate validator class that contains all validation logic and that can be used by all application classes....

You think it would be wise to put the Validator class on top and let any application class (Room, Member, Appointment) extend it?

Share this post


Link to post
Share on other sites
i'm actually not clear on the idea of extending a class with another.  what i intended to say was it's probably easiest just to create a validation class that you can use from within any other class, since it will be standard regardless of the application accessing it.  not sure how to achieve that though, since i don't use OOP (nor do i know the technical term for it).

Share this post


Link to post
Share on other sites

×

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.