encapsulation, typing & other questions

Jeff Shannon jeff at ccvcorp.com
Thu Feb 7 15:32:28 EST 2002


Ragu Bharadwaj wrote:

> Hi Guys,

Hi!  I'll only answer the questions that I feel qualified to say anything on...


> 2. How easy is it to use design patterns in Python? A lack of typing
> suggests it wouldn't be too easy, but I'd like to hear back from folks
> that have tried this.

It's very easy.  Many design patterns seem to almost be built-in to Python, many
others can be expressed in only a few lines of code.  The patterns that *don't*
seem to apply to Python, in fact, seem to be the ones whose whole point is
evading the type system.  (Laura Creighton recently made a comment to this
effect, about the GoF "Design Patterns" book....)


> 3. Are there plans to include method & variable encapsulation in the
> object models in python? The answer I've heard is that since it's
> possible to overcome encapsulation by long or dirty ways, it isn't worth
> it. But my comeback is that if one sticks to the rules while coding,
> this won't happen and the resulting gains are worth it.

Python *does* have encapsulation.  What it doesn't have is strictly enforced data
hiding.  However, if one sticks to the rules while coding, then having that
enforcement is not necessary.  And when in a situation that doesn't quite fit in
what the rules were intended to cover, then having that added flexibility can be
very much worth it.

(Note that Python *does* have some level of data hiding, but it's deliberately
easy to circumvent.  Instead of enforcing secrecy, it simply asks "Please don't
look at this"... )

Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-list mailing list