Re: Difference between type and class
- From: Maric Michaud <maric@xxxxxxxxxxxxx>
- Date: Thu, 31 Jul 2008 15:18:03 +0200
Le Thursday 31 July 2008 13:32:39 Thomas Troeger, vous avez écrit :
De :
Thomas Troeger <thomas.troeger.ext@xxxxxxxxxxx> (Aioe.org NNTP Server)
À :
python-list@xxxxxxxxxx
Date :
Aujourd'hui 13:32:39
Can someone explain to me the difference between a type and a class?
If your confusion is of a more general nature I suggest reading the
introduction of `Design Patterns' (ISBN-10: 0201633612), under
`Specifying Object Interfaces'.
In short: A type denotes a certain interface, i.e. a set of signatures,
whereas a class tells us how an object is implemented (like a
blueprint). A class can have many types if it implements all their
interfaces, and different classes can have the same type if they share a
common interface. The following example should clarify matters:
Of course, this is what a type means in certain literature about OO
(java-ish), but this absolutely not what type means in Python. Types are a
family of object with a certain status, and they're type is "type",
conventionnaly named a metatype in standard OO.
There are three sort of objects in Python, in an inclusive order :
- ordinary object, or instance, they could not be instantiated or subclassed
(in general), and are all an instance of type "object" (or a subclass of it).
- types, or classes, are all instance of type 'type' (or a subclass of it),
they can be instantiated and they produce objects (ordinary object in
general) with theirslef as a type.
- metatypes or metaclass, are subclasses of "type", their instances are new
types.
For all tjis work together you must admit the following recursivity :
'type' is both a subclass and an instance of 'object' while 'object' is an
instance of 'type'.
--
_____________
Maric Michaud
.
- References:
- Difference between type and class
- From: Nikolaus Rath
- Re: Difference between type and class
- From: Thomas Troeger
- Difference between type and class
- Prev by Date: Re: Difference between type and class
- Next by Date: current week / weeks in year - best practice
- Previous by thread: Re: Difference between type and class
- Next by thread: Case tagging and python
- Index(es):
Relevant Pages
|