Why does python not have a mechanism for data hiding?

alex23 wuwei23 at gmail.com
Mon May 26 20:48:41 EDT 2008


On May 27, 6:02 am, "Russ P." <Russ.Paie... at gmail.com> wrote:
> But I also believe that some standard way should be available in the
> language to tell the client (and readers of the code) which methods
> are *intended* for internal use only. And that method should be based
> on more than a naming convention. Why? Because (1) I don't like
> leading underscores in my identifiers, and (2) I think I should be
> free to choose my identifiers independently from their properties.

Have you considered using the Bridge pattern to separate your
interface from your implementation?

    class Implementation:
        def private_method(self):
            raise NotImplementedError

    class Interface:
        def __init__(self):
            self.imp = Implementation()
        def public_method(self):
            self.imp.private_method()

No offensive _methods on the interface, and the implementation is
still open for consenting adults to tinker with.



More information about the Python-list mailing list