[Tutor] newbie-class differs from function?
Erik Price
erikprice@mac.com
Mon Mar 10 09:19:01 2003
On Monday, March 10, 2003, at 08:44 AM, Lugo Teehalt wrote:
> Have got very stuck and it might help if I
>
> understood the difference, in hyper-simple terms, between
>
> a class and a conventional, programmer defined function.
>
> They seem the same to me.
Similar, but different. At its simplest level, I tend to think of a
function as a named, reuseable piece of code that you can explicitly
call to perform some action or return some value. (There are
exceptions, such as unnamed functions with lambda, but whatever.) You
can put a function anywhere in your code, but you have to "call" it (in
Python this is done by putting parentheses and possibly arguments after
the function) in order to get it to work.
At its simplest level, I tend to think of a class as a template of
sorts -- a description. Using this template or description, I can
crank out any number of objects that are defined by this template or
description. Each object conforms to the class that defines or
describes it. A class description generally consists of attributes
(each attribute being a variable specific to any given instance, or
object, of a class), and methods (each method being a function specific
to any given instance, or object, of a class). While all members of
class "Foo" have all attributes and methods defined in "Foo", the
actual data *in* those attributes or *returned by* those methods may be
different depending on the instance, or object, in particular.
That's just my 2 cents worth of a brief introduction, others on this
list are better at explaining it.
Erik
--
Erik Price
email: erikprice@mac.com
jabber: erikprice@jabber.org