> 
> Even though "tens", "ones" and "number" all appear as attributes, only
> "number" has its input validated.  Since the class is designed to only
> hold numbers 0 - 99, one can 'break' it by setting self.tens=11, for
> example.  Should tens and ones be made into full-fledged properties
> and validated?  Should number have no validation?  Is it more pythonic
> to encapsulate tightly, or rely on "responsible use."

You could make them double-underscored attributes. That creates some
name-mangling that prevents accidential access. But as there is no real
private concept in python (and java and C++ protection can be easily
overcome), it is considered pythonic to rely on responsible use.  If a
design for abuse-protection is the ultimate goal, the common suggestion is
to use IPC mechanisms to prevent in-process sharing of data and code -
that's the only real way to go, regardless of the used language.

-- 
Regards,

Diez B. Roggisch
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to