|
Posted by Carl on 09/26/51 11:34
Simon Dean wrote:
> Thing is though... what if you just want to list a series of Actors that
> you have on file (this is totally fictiional - It could be Orders Order
> OrderDetails OrderDetail Customers Customer etc...
I think you may want to take a step back and think closely about what
exactly you think an object is. The <Actor> is a valid object IMO,
<Actors> is not; It is simply a collection of <Actor> Objects (a.k.a an
array in php).
If you really want to be able to produce a list of actors in an OO
manner, you may consider a class such as <ActorManager>, which when
instantiated contains a collection of actor objects. It may also have
the ability to limit the actors it 'represents' based on criteria such
as age, sex, experience, etc.
>
> eg, at work, we might have a Customer belonging to Customers as a
> collection, but a Customer can belong to an Order too, and an Order
> contains many OrderDetail classes which can be retrieved through
> OrderDetails etc.. etc.. complicated to explain for me...
Are you using a database to store your Customers/Actors, if so, you may
want to consider the fact that you already have a 'collection' of
Customers/Actors inherent in the db table itself. Rewriting this
collection in code without abstracting it further or adding additional
functionality gives very little reward for the effort.
The relationship between customers/orders/order details you describe is
a very standard "one to many" relationship.
>
> Any how, back to my original observation... yes, what if I just want to
> show an "actor" listing and therefore, I just want to load a particular
> selection criteria and loop through as I would with while($line =
> mysql_fetch_array($result))) { } (hey, did I just remember some coding?)???
Again, i would suggest something like the <ActorManager> class I
described above, for example...
/*
* print the name and age of all actors between 18 and 30 years old
*/
$manager = new ActorManager();
$manager->setMinimumAge(18);
$manager->setMaximumAge(30);
$actors = $manager->getActorList();
foreach($actors as $actor) {
echo $actor->name."\t".$actor->age."\n";
}
>
> I can get the MySQL results, I can even get an array of the result and
> that can be accessed by through the class... but the main program would
> still need to know about the database design... Ideally, Im thinking, I
> could be wrong, I'd want to load each Actor record into a set of vars
> within the class to present back that the main program can then pick up
> the ones it wants to display them... But that means I would need to
> create lots of Actor objects... but I can't necessarily tell $this to
> create an array of itself do I? Hence I think is the idea to create a
> wrapper in essence, a collection of Actors that does have an Array of
> Actor classes, so we can loop through those and present them back to the
> main program...
>
> does that make sense? i think I totally lost myself.
>
> Cheers
> Simon
Hope that helps,
Carl.
Navigation:
[Reply to this message]
|