Form Validation Class

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

ghost007
Forum Commoner
Posts: 49
Joined: Sat Nov 22, 2003 10:10 am

Post by ghost007 »

you can call just what you need rather than putting them all in one big class
I noticed some articles on how doing this but I don't really see the advantage of putting them all in different files?

Is this to improve performance?

thx
siech
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

It's an example of lazy loading: rather than defining different validation methods in one class, you'd extend a common Validator base class with nice 'n slim classes which perform different types of tests.

The performance gains would admittedly be more theoretical rather than real. Possibly the extra HD seeks would even count against Strategy, depending on just how many validation methods you have defined in the all-in-one class. We're into Hubble telescope territory though: there wouldn't be any noticable difference either way, I think.

Strategy just feels better - leaner and meaner like good OOP classes should be.
User avatar
lazy_yogi
Forum Contributor
Posts: 243
Joined: Fri Jan 24, 2003 3:27 am

Post by lazy_yogi »

Oh Ghost, I forgot to mention something I heard somewhere (forget where)

The way you inherit from your config file doesn't meet the requirements of inheritence.

You should only inherit from something if there is an "is a" relationship. For example, a customer "is a" person and an employee "is a" employee, so they could both inherit from a person object, but a config file doesnt meet that requirments for a framework.

So I think it's best to have a config object as an attribute of other classes, rather than inheriting from it. It makes sense to me, so I thought I'd mention it incase you were interested.

Take it easy,
Eli
ghost007
Forum Commoner
Posts: 49
Joined: Sat Nov 22, 2003 10:10 am

Post by ghost007 »

nice thx for input guys. 8)

yogi using the phpframe logic I would for example use a constructor in the beginning of my mysql class:

Code: Select all

<?php
	function __construct()
	{
		$this->cfg = $this->createObject('config');
	}

?>
and than call all vars from config class as this:

Code: Select all

<?php
$link_id = mysql_connect($this->cfg->dbhost, $this->cfg->dbuser, $this->cfg->dbpass);
?>
correct :roll: ?

siech
User avatar
lazy_yogi
Forum Contributor
Posts: 243
Joined: Fri Jan 24, 2003 3:27 am

Post by lazy_yogi »

Yep. Exactly.

Tho, for readability, you could call the variable $this->config
The exta 3 letters doesnt clutter up the code, and make it more readable.

Cheers,
Eli
Post Reply