Strategies for controling attribute assignment
sholden at holdenweb.com
Tue Oct 2 14:33:53 CEST 2001
"Dale Strickland-Clark" <dale at riverhall.NOSPAMco.uk> wrote in message
news:9lajrtcqsojv72nr88c7j6kmdapjo44vc0 at 4ax.com...
> A 'properly' encapsulated business class tends to involve methods and
> attributes. However, managing attribute assignment gets very messy
> with __setattr__ as you need to devise a scheme to distinguish class
> attributes and working instance variables.
> Often, externally visible class attributes need to be validated and
> instance variables don't. Or they may get stored elsewhere.
> What strategies have people come up with to manage this distinction
> without bogging the code down in excessive checks.
> I would really like a way to distinguish between these two without
> having to check dictionaries.
I'm not quite sure what problem you are trying to solve here. Are you
suggesting that your code will change some class attributes and some
instance attributes to parameterize the operation of all instances for a
particular context. Maybe I need another cup of coffee ...
Well, the coffee was a good idea. Your problem is that when you *use*
__setattr__ you need to know whether you are setting a class or an instance
variable, right? And you want to set class attributes from inside methods?
Perhaps you'd explain what you mean by "proper" encapsulation is a problem
in your particular context. I'm presuming that you are working in a COM
environment, but of course I've been wrong before...
PS: See recent thread on not hiding your email address from spam!
More information about the Python-list