On 8/25/05, Greg Woodhouse <[EMAIL PROTECTED]> wrote: > How do you achieve polymorphic behavior? A few ideas occur to me such > as having a "CREATE" operator that sets the methods to the appropriate > implementations for the runtime type. Another is to maintain a table of > object IDs and classes and always have methods invoked through a common > dispatch manager, but nothing really seems very clean.
I am no OO expert. But I think that polymorphic behavior means that if you have an object heirarchy like this: Bird +- Jay +-Blue +-Gray And then having two objects, one Gray and one Blue, placed into variables p1 and p2. Then calling a ".chirp" function, would evoke two separate functions--assuming that the two objects had been given different chirp functions. Assuming that my understanding is correct, then I would probably set up my "object" by creating the parent object, then calling the setup procedure for each subsequent child in turn (i.e. merging the array first with the parent object). Child functions would then overwrite the parent's. Thus one might end up with an array-object that looks like this Bird("sClass")="Aves" Bird("bCanFly")=1 Bird("fncChirp")="w ""squawk"",!" Jay("sClass")="Aves" Jay("sFamily")="Corvidae" Jay("sOrder")="Passeriformes" Jay("bCanFly")=1 Jay("fncChirp")="" <-- no behavior here. BlueJay("sClass")="Aves" Bl;ueay("sFamily")="Corvidae" BlueJay("sOrder")="Passeriformes" BlueJay("sSpecies")="Cyanocitta" BlueJay("bCanFly")=1 Bird("fncChirp")="w ""Jeer Jeer"",! GrayJay("sClass")="Aves" GrayJay("sFamily")="Corvidae" GrayJay("sOrder")="Passeriformes" GrayJay("sSpecies")="Perisoreus" GrayJay("bCanFly")=1 Bird("fncChirp")="w ""Ge-att Ge-att"",!" Then when I do this: p(1)=$name(GrayJay) p(2)=$name(BlueJay) I can then use: for i=1:1:2 xecute @p(i)@("fncChirp") Jeer Jeer Ge-att Ge-att I think this shows how inheritence and polymorphism can be implemented. But again, my teminology may be off. Kevin > > Anyway, I remember that, and I think it's a good idea. > > --- Kevin Toppenberg <[EMAIL PROTECTED]> wrote: > > > A while back I posted code that used globals to store object-like > > data. Once can put functions (or references to functions) into a > > string (stored in the object) and then executed with the "xecute" > > command. > > > > Thus one could shoe-horn object orientated behavior from M > > > > Kevin > > > > > > === > Gregory Woodhouse <[EMAIL PROTECTED]> > > "Design quality doesn't ensure success, but design failure can ensure > failure." > > --Kent Beck > > > > > > > > > ------------------------------------------------------- > SF.Net email is Sponsored by the Better Software Conference & EXPO > September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices > Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA > Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf > _______________________________________________ > Hardhats-members mailing list > Hardhats-members@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/hardhats-members > ------------------------------------------------------- SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf _______________________________________________ Hardhats-members mailing list Hardhats-members@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hardhats-members