|No such thing as a small change|
OO Application Designby Nomis52 (Friar)
|on Sep 25, 2002 at 04:09 UTC||Need Help??|
Nomis52 has asked for the
wisdom of the Perl Monks concerning the following question:
I keep hearing about how when designing database based apps, the database access should be kept in the low layers (or in this case objects)Take a person object for example,
This would INSERT the entry in the db when new() is called, and do a SELECT when gettAge() is called.
The relation in the db may look something like this:
Now the thing that I can't get my head around yet, is how say getAdults() should work. So far I have come up with 2 possble ways to do this:
The first way I thought of was to have getAdults() as a class method which would run the SELECT .. WHERE on the db and return an array of people. By doing it like this it keeps all the code accessing one table in one class. Probably a Good Thing.
The second would be to create a separate class say PersonLister which contained the method getAdults(). I think this way is more OO in the sense that the Person class knows only about people, and higher classes know how to fetch groups of people.
What are the monks thoughts on this? Is either of these the prefered way to do this or am I completly missing something?
Fixed typo per author's req. - dvergin 2002-09-24