[Tutor] OO terms and definitions
Sun, 09 Dec 2001 13:42:38 -0500
On Sun, Dec 09, 2001 at 10:27:45AM -0800, Frank Peavy wrote:
> I am a little(or is that a lot) confused about some OO terminology.
> I have some quite a bit on the web and I have seen all sorts of definitions
> for the following terms:
> It seems to me that there is a hierarchy to some degree, as idented above.
> And, I am under the impression that a Module is usually a file with a .py
> extension that contains the other items.
> Does a Module always have a Class? I am under the impression that this is
> not the case.
You're right. Class is a "kind" of something. For example, you might
have a class Tree, 2 subclasses - Pine and Oak, and 2 instances of Pine
- pine that grows in your garden and pine that grows in Central Park in
> How do Function, Method and Procedure differ? Or are they the same...?
Procedure is just another name for a function. Function is some code
that is grouped under one name and can be called and executed using that
name. Method is a function that is associated with an object - for
example, the Pine class may have a method called die that would kill the
pine when run.
# method that runs when class is instantiated
self.alive = "yes"
self.alive = "no"
print "This tree is dead now."
# I don't remember exactly but I think the __init__ method is an
# exception because you have to explicitly re-run it in inherited
# class.. die method will be inherited automatically
Tree.__init__() # run Tree's __init__
my_garden_pine = Pine() # make an instance of Pine (instantiate
print my_garden_pine.alive # will print "yes"
my_garden_pine.die() # run die method; will print "this tree
# is dead now"
print my_garden_pine.alive # will print "no"
> Tutor maillist - Tutor@python.org
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org