What is a class?
A class is the particular object type created by executing a class statement. Class objects provide common behaviour, including code (methods) and shared data (attributes), for instances of a given data type (class).
A class can be based on one or more other classes, called its base class(es). It then inherits the attributes and methods of its base classes. This allows an object model to be successively refined by inheritance. You might have a generic Mailbox class that provides basic accessor methods for a mailbox, and subclasses such as MboxMailbox, MaildirMailbox, OutlookMailbox that handle various specific mailbox formats.
CATEGORY: programming
Comment:
Objects in Python have data attributes (to hold values that programs can retrieve by name) and methods (which programs can call to perform operations on the objects). Each different object will have its own attribute values, but all objects of the same type normally have the same methods. So it's convenient to specify the methods in a single place called the class definition. A class is therefore really a definition of the API of a particular type of object. [Not intended to be final, just to give some ideas. I tried to explain this for beginnners in Python Web Programming, so maybe I should look up my notes ...]
Posted by holdenweb (2006-11-03)
Comment:
The use of "template" might be a bit misleading here, since Python isn't prototype-based. Could explain how the class object holds "shared" content instead.
Posted by Fredrik (2006-10-30)