On 10.01.2013 19:50, Mitya Sirenef wrote:
On 01/10/2013 09:06 AM, richard kappler wrote:
class Tree(object):
height = 0
def grow(self):
self.height += 1
You may have a dozen of related functions and you can logically group
them together by making them methods of a class, making it easier to
think about and work on the logic of your program.
Actually one question about those "dozens of related" instances
generated by:
greenwoodTree = Tree()
oakTree = Tree()
....
Both, greenwoodTree and oakTree, are derived from Tree class, thus
receiving the features and also - if so - holding unique values created
in there __init__ generator method - "self.height", "self.color" and so
forth uniquely each.
But do both share the same function memory space from the class "Tree"?
I am currently trying also to get my head wrapped around OOP in general,
but not 100% sure so that derived instances use the same functions (also
memory wise speaking) - or are there several definitions of "grow" ?
The confusion came somehow when reading about "classmethods" and
"staticmethods" and patterns like Singleton, monostate, borg...
from which I understand only ensure that the "self.height" properties
are shared across multiple instances of a given class?
From what I tried out using id() and generating functions in a loop -
the "id(class.function) provided the same result when printed out,
according to that:
http://stackoverflow.com/questions/121396/accessing-object-memory-address
So I assume the functions are shared across thus one decleration has
been made in "Tree" class and all siblings are using that one?
Thank you in advance for clarification.
Jan
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor