ui factory - what should it do?
Robert Collins
robertc at robertcollins.net
Fri Feb 24 12:44:01 GMT 2006
On Fri, 2006-02-24 at 10:53 +1100, Martin Pool wrote:
> > Because if I were to convert fetcher to have a do-it method, I'd put the
> > entire body of the __init__ method there. And then I'd have to restore
> > the members to safe values afterward, so no unsafe member functions
> > could be called.
> >
> > There is definitely a need for an idiom represent a procedure with
> > multiple phases and shared data, where that shared data becomes obsolete
> > at the end of the procedure, and this way didn't seem so bad, on reflection.
>
> I don't really mind it, and agree with your point about the member
> fields. I think I've created at least one such class myself.
>
> My main thing was that we should perhaps make classes like this
> consistent with each other. If no one dislikes doing it in __init__ we
> can use that.
I really don't like putting 'do it' logic in __init__. Several reasons.
If you want to pass in a parameterised worker object, you can't do that
with __init__ doing the work, instead you need to pass in a customised
factory function. Its more flexible therefore to construct objects that
can perform the task and then ask them to perform it. Most of the time
you won't need that, but when you do its nice not to have to jump
through extra hoops.
I'm also not happy with using __call__ in case anyone is wondering, as
it can be extremely confusing to have a callable instance of an object.
W.r.t. the reuse of member variables: We're not talking about having
these objects around for indefinite periods : I don't think coding every
one of them for serial-calls is sensible, I'd ignore the issue until you
have a use case for reusing an instance of one of these objects.
Rob
--
GPG key available at: <http://www.robertcollins.net/keys.txt>.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060224/5836aa3a/attachment.pgp
More information about the bazaar
mailing list