On 23/01/16 04:14, boB Stepp wrote:

> humdrum.sigh_strenght = 'high'
> 
> was accepted and did not generate an error, it seemed to mean to me
> that I was violating my object's data encapsulation.  

In fact you were adding to its encapsulation(*).
Encapsulation means putting things in a box. You were adding to the
box's content therefore increasing its encapsulation. Python is one of a
few languages that allow you to do this, it's not a common feature.
Javascript is the other commonly known example.

(*)Some OO texts wrongly imply that encapsulation is about hiding
details. That's abstraction, or data hiding. These are related
but different qualities. encapsulation is a necessary feature
of OOP - it's what defines an object: having data and function
in a single box that you can then pass around. Data hiding
is an optional feature not necessary to OOP but useful in
preserving the integrity of the object.


> similar to having a class Dog, to which from outside the class'
> definition, I decide to add a new Dog attribute that all dogs in this
> class can now have a tail sticking out of their noses.  

No, you only add the attributes to an instance. Its like
giving your pet spaniel a radio beacon under its skin to track it.
Only your dog has that not all of the spaniels in the world.

> qualms about subclassing Dog with a MutantDog subclass, but adding new
> attributes from outside the class definition?  That just does not seem
> right to at this point of my understanding.  

We do it all the time in the real world. But its not that common
in programming, mainly because how do you tell the existing code
about the new attribute?


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to