Date manipulation and Java 'interface' equivalents

Martin Christensen knightsofspamalot-factotum at mail1.stofanet.dk
Fri Nov 10 16:30:39 EST 2000


>>>>> "Alex" == Alex Martelli <aleaxit at yahoo.com> writes:
>> However, for some operations I want to manipulate these objects
>> without necessarily knowing what kind of objects they are.
Alex> Yes: polymorphism.

There isn't much consistency in what people mean by 'polymorphism'
other than it having to do with accounting for different shapes of
whatever. At least this is my experience.

>> 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.
Alex> In Python, you accomplish this in a simpler way: a. have your
Alex> objects define the methods you desire to call (whether by
Alex> inheriting them, or directly); b. have your client-code calls
Alex> said methods on the objects.
[...]

Of course! How stupid of me to not have seen this right away! My
statically typed luggage weighs heavily on my young shoulders. :-) Of
course this makes it all so much easier, although it does it would be
nice to have some sort of check to see if the classes in question do
in fact respect the required convention. But that's acheived trivially
by an external test routine, if such a feature is really desired.

Thanks for your elaboration. It was very helpful; I just needed my
duh-switch to be flipped. :-)

Martin

-- 
GPG public key: http://home1.stofanet.dk/factotum/gpgkey.txt



More information about the Python-list mailing list