Hi,
Monday, October 6, 2003, 3:20:08 AM, you wrote:
GS> Dan Anderson wrote:
>>Out of curiousity, what exactly are you trying to do? Are you sure this
>>type of framework is most appropriate (and easiest to implement?)
>>
GS> In my current setup, the more classes Im adding to the code, the more
GS> complex things seem to get.
GS> For example.
GS> I have a smarty object that has a reference to a DB object.
GS> I plan on converting a file of user management functions to a class.
GS> If I do, then that new class, is going to need a reference to the DB object.
GS> Then on top of that, the smarty object is going to need a reference to
GS> the user management object.
GS> By the time we are here, the smarty object contains a reference to the
GS> DB object, *and*
GS> a reference to the user management object which contains a reference to
GS> the DB object.
GS> And thats just the beginning. There are other classes that intertwine
GS> in this manner.
GS> So what I would I forsee as a better playing ground would be
GS> 1. child classes being capable of talking to each other
GS> For example, the smarty class capable of calling the DB class and the
GS> user management class
GS> without the need for all those redundant *large* references.
GS> 2. The parent class capable of talking to the child classes.
GS> In this context, parent and child is not to be thought of as in normal
GS> class structures where children *extends* parents.
GS> All the *parent* class is, a means to provide wrappers around other
GS> *child* classes,
GS> and act as a controller. The *child* methods/variables,
GS> aren't/shouldn't be called directly.
GS> Also, if I can work it out, the class mm would only intially contain a
GS> constructor, and maybe a
GS> class loader.
GS> The class loader provides the additional class method wrappers on demand
GS> when needed.
GS> This is merely an first rate idea. Nothing is remotely concrete about it.
GS> Thanks for looking.
To do this I have my classes register themselves in a global array.
For example a mysql class which gets used a lot does this in its constructor:
function mysql_class($db='',$ini=''){
global $class_ref;
$class_ref["mysql_class"] =& $this;
.
.
.
}
Then any class that needs access to mysql_class does this in the constructor:
class galleryClass(
var $mysql;
var $db = 'test';
function galleryClass(){
global $class_ref;
if(!empty($class_ref['mysql_class'])):
$this->mysql =& $class_ref['mysql_class'];
else:
$this->mysql = new mysql_class();
endif;
if(!empty($this->mysql)):
$this->con = $this->mysql->get_handle($this->db);
endif;
.
.
}
.
.
}
This way there is only need for 1 instance of the mysql class.
I use global as a bad habit, but you can do the same with $GLOBALS['class_ref']
--
regards,
Tom
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php