Hi Chris

I am currently busy with a similar experiment for a project of my own and my
OOP knowledge is similarly limited :). I have had a fair degree of success
(by my humble standards) and  I am currently trying to make the process as
session-friendly as possible. I have a single class (call it Class A) that
is used to track db connections and certain environment variables (e.g. user
name and id). When I construct other classes (Class B, Class C....Class n)
that are specific to only portions of my application I pass Class A to these
lower classes via their constructor.

My problem is : If I make changes to my instance of A, after B or C is
instantiated, I have to manually reset B or C so that they reflect the
changes to A whereas I would prefer some sort of pass_by_reference mechanism
that would give each instance of B and C a pointer to the instance of A, so
that they would be automatically updated. Because I am stubborn, I am going
to try and solve this myself before I post a "Please Help" to the list, but
I would be happy to compare notes with you (or anyone else) offlist if you
so wish.

Regards

Rory McKinley
Nebula Solutions
+27 82 857 2391
[EMAIL PROTECTED]
"There are 10 kinds of people in this world,
those who understand binary and those who don't" (Unknown)

----- Original Message ----- 
From: "Chris W. Parker" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, October 15, 2003 1:51 AM
Subject: [PHP] class/object design


Hey peeps.

Let me try to make this simple. Right now I have a base db class that is
moved solely for interacting with the db. It opens the connection, runs
queries, and returns the results of those queries. Along with this class
I've got some other classes (I'll call them "upper" classes) that are
used to interact with different aspects of my project. For example I've
got a Products class (used to add/delete products, etc.) and a Category
class (used to add/delete categories, etc.).

Currently I'm extending the base db class into these "upper" classes.
i.e.

class DB
{
function dostuff ()
{
}
}

class Products extends DB
{
function dothings ()
{
$this->dostuff();
}
}

On this list I read a post that suggested I not do it this way but
instead instantiate a DB object within each method of the "upper" class
whenever necessary (as far as I understood the recommendation).

This sounds like a good idea except that this would mean I'd be creating
and destroying a DB object each time a method in an "upper" class needed
to access the db. The way I'm doing it now requires that I only
instantiate one object for the entire page and let any method in that
"upper" class to share the connection.

With my limited knowledge of OOP the only solution I can see would be to
use a constructor in the "upper" class to instantiate the object when
the "upper" class object is instantiated.

Am I making sense and does anyone have any suggestions or comments to
add? Maybe something to straighten me out?



Thanks,
Chris.

--
Don't like reformatting your Outlook replies? Now there's relief!
http://home.in.tum.de/~jain/software/outlook-quotefix/

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

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

Reply via email to