Instances behaviour
Giovanni Bajo
noway at sorry.com
Sun Dec 4 05:20:12 EST 2005
Mr.Rech wrote:
> and so on. The problem I'm worried about is that an unaware user may
> create an instance of "A" supposing that it has any real use, while it
> is only a sort of prototype. However, I can't see (from my limited
> point of view) any other way to rearrange things and still get a
> similar behaviour.
1) Document your class is not intended for public use.
2) Make your A class "private" of the module that defines it. A simple way is
putting an underscore in front of its name.
3) Make your A class non-functional. I assume B and C have methods that A
doesn't. Then, add those methods to A too, but not implement them:
def foo(self):
"""Foo this and that. Must be implemented in subclasses."""
raise NotImplementedError
--
Giovanni Bajo
More information about the Python-list
mailing list