Why does python not have a mechanism for data hiding?

Russ P. Russ.Paielli at gmail.com
Tue Jun 3 06:11:58 CEST 2008


On Jun 2, 6:21 pm, alex23 <wuwe... at gmail.com> wrote:
> On Jun 3, 9:41 am, "Russ P." <Russ.Paie... at gmail.com> wrote:
>
> > Here's what I think Python should have. I think it should have a
> > keyword, something like "priv," to identify data or functions as
> > "private."
>
> As I stated earlier in this thread, if you want a public interface and
> a private implementation, rather than adding another language feature
> why not just separate them into two classes? This is exactly what the
> Bridge pattern provides and would clearly denote your intention in the
> code.

Yes, that looks interesting, but I think it has a couple of drawbacks.
First, it requires another completely separate class for the
"implementation" (although perhaps that could be a nested class).
Secondly, I think it essentially just adds a sort of inner namespace
through which the "private" data is accessed. That might be a good
idea, but I don't think it's quite the same as encapsulation.



More information about the Python-list mailing list