Date manipulation and Java 'interface' equivalents
Quinn Dunkan
quinn at dinar.ugcs.caltech.edu
Wed Nov 8 03:57:19 EST 2000
More information about the Python-list mailing list
Wed Nov 8 03:57:19 EST 2000
- Previous message (by thread): Date manipulation and Java 'interface' equivalents
- Next message (by thread): Date manipulation and Java 'interface' equivalents
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 07 Nov 2000 21:41:51 +0100, Martin Christensen <knightsofspamalot-factotum at mail1.stofanet.dk> wrote: >I'm not sure I get your point, and I'd much appreciate elaboration. I >have to manipulate different goods, say, knobs, dials and >blinkenlights, and each of these are represented by objects of >different classes, naturally. However, for some operations I want to >manipulate these objects without necessarily knowing what kind of >objects they are. In Java I would accomplish this by having them >implement an interfacy Thingy that enables me to throw them around as >I wish, and when I need the specific qualities of a certain class I >can cast the Thingy object to whatever's relevant. You'd do it exactly the same way in python, except there's no need to implement any sort of "interface". Your objects already have an interface: their methods. Throw anything anywhere you please, but don't bother writing interfaces or casts. You almost never need to know or even care what 'kind' an object is... just call whatever method you want on it. If it accepts the method, then that's all you need to know about its type (if it doesn't you get an exception). I.e. if your Knobs and Dials have a 'twist' method, that's all the client code cares about. It couldn't care less what 'class' they belong to. I think that's what Alex meant by the "the method is the type" stuff. Think of python as being a lot like Java, except instead of going through all the declaration verbiage to convince the compiler what you say you want is really what you want, just say what you want. python will believe you the first time :)
- Previous message (by thread): Date manipulation and Java 'interface' equivalents
- Next message (by thread): Date manipulation and Java 'interface' equivalents
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list