Page 2 of 2
Posted: Sun Apr 04, 2004 11:57 am
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
Posted: Sun Apr 04, 2004 2:09 pm
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.
Posted: Mon Apr 05, 2004 11:28 am
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
Posted: Mon Apr 05, 2004 4:25 pm
by ghost007
nice thx for input guys.
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

?
siech
Posted: Mon Apr 05, 2004 6:56 pm
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