Encapsulation unpythonic?

Ian Kelly ian.g.kelly at gmail.com
Wed Aug 21 18:02:57 EDT 2013


On Aug 21, 2013 10:53 AM, <random832 at fastmail.us> wrote:
>
> On Mon, Aug 19, 2013, at 3:05, Steven D'Aprano wrote:
> > In this toy example, both parties are at fault: the author of Parrot for
> > unnecessary data-hiding of something which is so obviously a useful
piece
> > of information and should be part of the public interface,
>
> It may wish to be notified when its name changes, and so have a name
> property.

The example as given has no such property, and regardless of whether it is
a property or an attribute the public API should just be called "name".

> The subclass may want to use a variable called _name for some
> other purpose. (maybe "name" isn't the best example).

Probably not a good idea for multiple reasons if the base class already has
something called "name".
 On Aug 21, 2013 10:53 AM, <random832 at fastmail.us> wrote:

> On Mon, Aug 19, 2013, at 3:05, Steven D'Aprano wrote:
> > In this toy example, both parties are at fault: the author of Parrot for
> > unnecessary data-hiding of something which is so obviously a useful piece
> > of information and should be part of the public interface,
>
> It may wish to be notified when its name changes, and so have a name
> property. The subclass may want to use a variable called _name for some
> other purpose. (maybe "name" isn't the best example).
>
> Examples often look pathological when you simplify out the bit that
> makes them make sense.
>
> --
> Random832
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130821/73bc04d0/attachment.html>


More information about the Python-list mailing list