python classes

William D. Gill wmgill at gcgroup.net
Thu Mar 4 14:42:07 EST 2004


"Peter Otten" <__peter__ at web.de> wrote in message
news:c27t0v$fhn$05$1 at news.t-online.com...
> William D. Gill wrote:
>
<<<<<------SNIP----->>>>>
> > class MyClass:
> >     def __init__(self, id=0000):
> >         self.data = MyOtherClass(id)    # data is an object with name,
id
> > and other properties
>
> I think this is an extra complication that gains you nothing. The only
> exception would be that data would not be initialized in
MyClass.__init__()
> but lazily at some later point, a usefull pattern if for a significant
part
> of the MyClass instances you can get away with not initializing data at
> all. You would then change MyClass as follows:
>
My thinking was to create a class for each table that contains pieces of the
whole customer information , and wrap OOPS! I mean include :)  those classes
in the overall customer class object.  That way by supplying id, all the
different constructors would go get the right data.

At my level (pre-novice) it's probably better to use one customer class and
sequential programming in the constructor:

select * from table A where id=1234
self.company_name = A.name
...

select * from table B where id=1234
self.mailto=B.mailto
self.billto = B.billto
...
select * from table C where id=1234
self.cell=C.cell
self.list=C.list
...
(using multiple selects because they may produce different size record sets)


<<<<<------SNIP----->>>>>
> I suppose that was a mutual misunderstanding. Did you mean this by
> "wrapping"?
>
> try:
>     customer = Customer.fromId(1234)
> except InvalidCustomer, e:
>     print e
Yes


Thanks,
Bill





More information about the Python-list mailing list