Ben Nadel
On User Experience (UX) Design, JavaScript, ColdFusion, Node.js, Life, and Love.
I am the chief technical officer at InVision App, Inc - a prototyping and collaboration platform for designers, built by designers. I also rock out in JavaScript and ColdFusion 24x7.
Meanwhile on Twitter
Loading latest tweet...
Ben Nadel at cf.Objective() 2014 (Bloomington, MN) with:

Exercise List: Form Data Validation Context In OOP

By Ben Nadel on

Click here to view the current Online Demo

Click here to view / download the current Code Base

Just a quick thought here on form data validation context in object oriented programming (OOP) and ColdFusion; As I was updating my ErrorCollection.cfc to be used by the Service Objects' Valiate() method, I realized that form validation must take into account the context, or rather the intent of the intent of the form. Form data isn't just valid or invalid; it's valid with regards to a desired action as different actions incur different business logic and rules. I don't have to deal with this in my application, as it is quite small, but take, for example, the Joint object. I don't even delete joints from the system, but if I did, I certainly wouldn't want to delete a joint that was associated with an existing exercise as this would corrupt the existing data.

So, zoom out a bit, if we were dealing with a joint, then we would have two different sets of validation logic:

Action: Update Joint

Validation Logic:

  • Is name of joint set.
  • Is name of joint a given length.

Action: Delete Joint

Validation Logic:

  • Is joint associated with an existing exercise.

Since the context is so important, you can't just have one validation method, Validate(), as I was planning to have. You have to have a validation method for each desired mutating CRUD action. I combine Create and Update into a single Save() method, so I would need:

  • ValidateDelete()
  • ValidateSave()

I feel like with every passing hour, form data validation in object oriented programming is proving to be harder and harder! Procedural programming makes this so easy, but not reusable at all (I know, I know, the payoff is there).



Looking For A New Job?

100% of job board revenue is donated to Kiva. Loans that change livesFind out more »

Reader Comments

I think the availability of OO techniques has gotten many CFers thinking that OO is the "one true path". You can write well-encapsulated, reusable code that isn't OO.

Reply to this Comment

@Steve,

I am a huge fan of ColdFusion custom tags, user defined functions, and general CFC-ery, but I figured, learning a new technique for something can never hurt. Clearly, there is a big learning curve for stuff like this, and maybe I will find in the end that it's just not for me; but, gosh darn it, I'm going for it :)

Reply to this Comment

I'm glad you are! Well worth it just to gain the experience. I love reading about it.

I was only objecting to the line "Procedural programming makes this so easy, but not reusable at all". Procedural programming doesn't guarantee that code can't be reusable.

Cheers!

Reply to this Comment

Post A Comment

You — Get Out Of My Dreams, Get Into My Comments
Live in the Now
Oops!
Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.