On Fri, 2003-10-03 at 10:23, Gerard Samuel wrote:
> Or is there such a thing.  ;)
> I have a small collection of utility classes, and it seems like the more 
> I add,
> the more cumbersome things seem to get.
> A brief synopsis of code execution.
> 1.  Start DB class
> 2.  Start Smarty class, passing reference of DB class to Smarty
> 3.  When needed start Date-Time class
> 4.  When needed start Text-Format class, passing reference of Smarty 
> class to Text-Format class,
> which also has a reference to the DB class.  (Im using both within the 
> Text-Format class)
> 
> Currently, I have a file of functions that handle user management, a 
> possible candidate for a class.
> If I were to convert it, it would go between steps 1 and 2, and would 
> need a reference to the DB class.
> Then the Smarty class is going to need a reference of the proposed user 
> management class.
> By that time, Smarty contains itself, a reference to the DB class, 
> reference to the user management class which
> in turn contains a reference to the DB class.
> All these references, are beginning to worry me, to the point where Im 
> second guessing myself, that
> Im going about this the wrong way.
> Making "utility" classes are somewhat straight forward, but getting them 
> to work together,
> seems like a pain.
> 
> So I was thinking, if a class was started in the global space, is it a sin,
> to use the $GLOBALS array to access it, instead of tying in all these 
> references??

I think reasons like your above are why people, quite often these days,
create frameworks. Frameworks are generally designed from the ground up
to provide the kind of interactions you are moving towards while at the
same time, loosely coupling the interactive pieces to provide
flexibility. With regards to the question of sin -- most books regard
them as dirty dirty little beasts. That said, the entire PHP philosophy
revolves around globals. In my opinion though, the internal globals used
by PHP are fine, but blatant creation by your own code is generally a
design flaw. There are times when it is useful to create a global, for
instance I encapsulate all of my framework's data via a single globals
variable ($GLOBALS['interJinn']). A purist might argue that this is bad;
however, the purist could not do any better since to create an object to
hold such data would still require an anchor point somewhere in the
global space. From this I think it follows that too many global
variables -- poor design. The occasional global variable -- good design
(notwithstanding other design issues :)

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to