Tardis has asked for the wisdom of the Perl Monks concerning the following question:
If we use the example from perltoot which some of you may be familiar with, or at least have available, a class is developed for managing 'Person' objects. What I'm developing is similar enough to the Person example.
In my code, I have some objects for storing data, but I'd also like a search function. My objects are identified by an integer id - because they are going into an SQL DB at this stage.
However I'd like to be able to do searches. The natural inclination is for a search method which returns a list of integers, each of I could pass to my 'fetch' method on a new object on to get the data in.
However this doesn't quite 'feel' right. For example, I need to do a $thing->new to initialize the object so I can use the $thing->search method. So I've allocated storage, created an object that didn't need to be made.
Of course this is all semantic - but it's not obvious to me in what way I've got it 'wrong', nor how to implement it 'right'.
Can provide more detail if needed, but it's basically very similar to the 'Person' class from the manpage, with some added store and fetch methods to do SQL stuff.
Would appreciate some insights from more experienced OOP programmers.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Beginner OOP style question
by rjray (Chaplain) on Mar 02, 2002 at 08:12 UTC | |
by Tardis (Pilgrim) on Mar 02, 2002 at 08:39 UTC | |
by jeffa (Bishop) on Mar 02, 2002 at 13:21 UTC | |
by fuzzyping (Chaplain) on Mar 02, 2002 at 13:37 UTC | |
by Anonymous Monk on Mar 02, 2002 at 20:49 UTC | |
Re: Beginner OOP style question
by Zaxo (Archbishop) on Mar 02, 2002 at 09:12 UTC | |
by thpfft (Chaplain) on Mar 02, 2002 at 16:47 UTC | |
Re: Beginner OOP style question
by steves (Curate) on Mar 02, 2002 at 10:00 UTC | |
by dragonchild (Archbishop) on Mar 04, 2002 at 14:25 UTC | |
Re: Beginner OOP style question
by ixo111 (Acolyte) on Mar 02, 2002 at 16:35 UTC |