swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dynamic binding?


From: James Marshall
Subject: Re: dynamic binding?
Date: Tue, 21 Jul 1998 16:36:29 GMT

Hi,
  well, that's a shame! Seems to me that what I want to do could have 
been done quite easily at run-time... because the different methods 
are implemented in different object classes all that should be 
necessary is to check what type of object is being messaged at 
runtime, then use the method implemented in that object class? No 
need to check the return types at all, as far as I can see. 
Presumably that's what happens when different object classes present 
identical method interfaces as you describe?
  Also the ObjC didn't differentiate between methods with the 
same name but different parameter types, which I'm sure you can do in 
C++? Perhaps it was my fault in this case, if my code was ambigous at 
compile time. I guess then I could have removed the ambiguity by 
casting the parameters to ints or doubles as appropriate to force the 
selection of the right method? But anyway, surely the first case for 
identifying the method to use based on receiving object type still 
holds?
  Back to the drawing board I guess... thanks for the help,
        James

> At 02:27 PM 7/21/1998 GMT, James Marshall wrote:
> >Hi,
> >  I have a problem when compiling my Swarm app now, because I have 
> >two objects each with a method of the same name (but taking 
> >and returning different format parameters (ints or doubles). When I 
> >try to compile this the compiler warns of the multiple declarations 
> >and chooses one to use at compile time. Why does this happen? I 
> >though Objective C was supposed to allow polymorphism and dynamic 
> >binding? i.e. the method to use should be chosen at run-time, not 
> >compile time, after examination and determination of the type of the 
> >object receiving the message? 
> 
> Well, yes, but that means different object classes are allowed to implement
> the same method in different ways -- but 'the same method' means the
> different implementations have to define the method interfaces in the exact
> same way. I.e., you can have different classes implement '-(int)getData' in
> different ways. 
> 
> However, objectiveC keeps a single 'database' of method definitions, and it
> is a limitation of the language that you are not allowed to have synonymous
> methods returning different data types. So if you first define
> '-(int)getData', you have an illegal duplicate when you define
> '-(double)getData'. (It was probably too much work to build in the
> necessary 'magic' to check at runtime for what size the return value is.)
> 
> Sorry 'bout that!
> 
> Cheers,
> --Sven
> 
> 
>                   ==================================
>    Swarm-Support is for discussion of the technical details of the day
>    to day usage of Swarm.  For list administration needs (esp.
>    [un]subscribing), please send a message to <address@hidden>
>    with "help" in the body of the message.
>                   ==================================
> 
--
James Marshall - Postgraduate Research Student (MPhil/PhD)
Artificial Intelligence Group - Department of Computer and Information Sciences
De Montfort University - Milton Keynes Campus
Web:- http://www.mk.dmu.ac.uk/~jmarshall/

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.
                  ==================================


reply via email to

[Prev in Thread] Current Thread [Next in Thread]