|
Posted by Simon Dean on 10/24/02 11:34
Carl wrote:
> 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.
What's the difference then, between your ActorManager and my Actors class?
> 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.
Don't get me wrong, I quite agree. This is just the structure we use at
work where we get everything from the database and represent everything
in classes and then more... It's never made much sense to me, because
nothing is really being simplified in the process... the error handling,
save and load routines are being standardised though I guess... but
that's about it....
>
> 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"; }
In this instance, presumably the set's are a backend to produce a where
statement, the getActorList loads the query data into a selection of
Actor objects, which again, doesn't sound too different to my Actors
class... perhaps I never explained it properly...
Thanks
Simon
Navigation:
[Reply to this message]
|