OOP: How to implement listing al 'Employees'.

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Fri Dec 28 13:33:00 EST 2007


Petar a écrit :
> On 28 dec, 13:40, Bjoern Schliessmann <usenet-
> mail-0306.20.chr0n... at spamgourmet.com> wrote:
> 
>>Petar wrote:
>>
>>>What is the better way of doing this? And should a class always
>>>reference only on 'item'?
>>
>>It fully depends on what you want to do in your program. If you just
>>want to have a list of employees, a list or dict will suffice. If
>>you need a full-fledged employee database, an "Employees" class may
>>be a good API.
>>
(snip)
> 
> It's a pure hypothetical question about where to put the function for
> the list of employees when already having a Employee class.

The problem with "pure hypothetical" questions is that they usually have 
no single good answer, and sometimes even no answer at all.

Now since you're talking database, the most common patterns seems to 
have either some YourDomainClassNameHere methods to query instances, or 
some module/singleton object providing such querying interfaces for the 
whole app (or FWIW to provide both, the first calling on the second...).

> Do I make it a method of the class, or do i create a instance of the
> class for every employee (sitting inside a list)?

If you have an Employee class, I don't get how you would avoid creating 
an instance for each and every, well, instance ? Unless you're thinking 
about something like MS "recordsets" ? But then, you don't need any 
domain class at all...



More information about the Python-list mailing list