Page 1 of 1

Function polymorphism

Posted: Wed Apr 15, 2015 10:40 am
by FredBeck
Hi,
I'm converting a C# library, which is pure OOP. So in this lib there is a constructor with a parameter, that instantiates the correct object.
In this particular case the object just contains one or two simple math functions. I came up with four ways of doing this.

1) "OOP in Livecode" style, very cool for GUI stuff, but I won't do this just for a couple functions...

2) Giant function with a "type" param and a switch, not cool because I want these functions to be stored in separate buttons. It's a part the user might want to extend or fiddle with.

2b) Interface function and calls to buttons in the library stack

3) insertion in backscript of the correct script in place of constructor

I'm not sure which to choose between 2b) and 3).
Regarding 2b, I don't really like the syntax of call. Well that's about it...
As for 3, I can only have on form of the function available, meaning I may have to insert/remove scripts quite frequently into/from the backscript. Is this safe?
I'm concerned about performance too.

Fred.

Re: Function polymorphism

Posted: Thu Apr 16, 2015 1:22 am
by dunbarx
Hi.

Have you considered using behaviors? This is OOP, right up your alley.

But all of the other options you mentioned are viable, because LC has features that allow you to identify and separate child objects. This allows you to properly execute any variants in functionality you might need in your "library" handler based on that child.

This is a basic tenet of xTalks, an extra layer, which includes the likes of "me", "the target", etc. to permit one to manage all those unruly children. With behaviors, the child object retains its own local variables, as well as references to "me".

Oh. Its fun, too.

Craig Newman

Re: Function polymorphism

Posted: Thu Apr 16, 2015 8:44 am
by FredBeck
Hi Craig, thanks for your response.
Well point 4 was written on the tip of my nose. I'm well aware of behaviors and I use them a lot.
Until 5 minutes ago, I didn't know you could set the behavior of a stack :) It doesn't show in the property inspector so I figured it was only for controls...
I should've rtfm, it's written black on white! Sorry ;)
Thanks again,
Fred.

Re: Function polymorphism

Posted: Thu Apr 16, 2015 3:16 pm
by dunbarx
Fred.
I should've rtfm, it's written black on white! Sorry ;)
Not at all. It SHOULD be in the inspector. Do you want to file the report or shall I?

Craig

Re: Function polymorphism

Posted: Fri Apr 17, 2015 9:00 am
by FredBeck
Craig,
If you think it's worth it, you'll probably do a better job at it.
But please don't postpone LC8 dp2 on my account!
F.