> > One personal suggestion: you could directly put the code from
> > initialize_customer() into the constructor.
>
> but i'm thinking that i might, at some point, want to use that method
> after the object has been instantiated. i can't think of a specific
> case, but i'm only imagining that it's possible.
It could be useful when retrieving real data is expensive.
I've been recently working with a data set that is derived from a
highly-relational database served over HTTP via XML. It's time consuming
to pull new information about a record and not all information is used
everywhere, so I've been using a structure similar to yours with a
lazy-load component -- the data source isn't actually accessed for a
particular piece of information until that piece of information is
specifically requested.
In the example below, properties one and two might refer to linked or
nested objects, each with a high cost of retrieval. The database access
code that is now in your initialize_customer() method gets split up into
logical chunks, and placed in the property_*() methods.
Paraphrased/contrived example:
class thing
{
var $id;
var $property_one;
var $property_two;
function thing($id)
{
$this->id = $id;
}
function get_property_one()
{
if(!$this->property_one) {
// perform request for property one,
// set $this->property_one
}
return $this->property_one;
}
function get_property_two()
{
if(!$this->property_two) {
// perform request for property two,
// set $this->property_two
}
return $this->property_two;
}
}
---------------------------------------------------------------------
michal migurski- contact info and pgp key:
sf/ca http://mike.teczno.com/contact.html
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php