Making immutable instances

Mike Meyer mwm at mired.org
Wed Nov 30 15:23:31 EST 2005


Paul Rubin <http://phr.cx@NOSPAM.invalid> writes:
> Mike Meyer <mwm at mired.org> writes:
>> Letting the class author declare whether or not the client can add
>> attributes is wrong for the same reasons - and in the same places -
>> that letting the class author declare that the client shouldn't be
>> allowed to access specific attributes, and so on, is wrong.
> The same logic can apply to what the class operations should do.  The
> answer is the same in both cases.  That's why subclassing and
> inheritance were invented.

Exactly. Adding an attribute is isomorphic to subclassing, except it
doesn't' take any boilerplate. Unless you do something to prevent
people from subclassing, they can always write the boilerplate and
pretty much continue as before. I don't believe there's a good reason
for preventing the boilerplate free method, and repeated requests for
a use case for this have gone unsatisied.

Have you got a use case?

  <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list