Re: Difference between type and class



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
.



Relevant Pages

  • Re: Design question - implentation and composition
    ... I have a design where it seems appropriate to use a tactic I haven't ... I've got four classes each of which subclass a common super class. ... implement each of the interfaces with a separate class. ... There is a lot of common functionality in the super class, the majority of the code resides here, however, each subclass must implement these interfaces, or somehow contain the methods that are in these interfaces. ...
    (comp.lang.java.programmer)
  • Re: Design question - implentation and composition
    ... I have a design where it seems appropriate to use a tactic I haven't ... I've got four classes each of which subclass a common super class. ... implement each of the interfaces with a separate class. ... I keep seeing the current heirarchy as the best. ...
    (comp.lang.java.programmer)
  • Re: Design question - implentation and composition
    ... I have a design where it seems appropriate to use a tactic I haven't ... I've got four classes each of which subclass a common super class. ... implement each of the interfaces with a separate class. ... factory pattern providing two factory methods. ...
    (comp.lang.java.programmer)
  • Re: object as parameter
    ... interfaces I've been contemplating the following questions ... you don't need to rewrite a method in a subclass that exists in the super ... As you will be using them as general reference tools from here on out. ... Interface inheritance merely means we have one object that supports mulitple ...
    (microsoft.public.vb.general.discussion)