Function polymorphism

Want to move your code and projects to LiveCode but don't know where to start?

Moderators: FourthWorld, heatherlaine, Klaus, robinmiller

Post Reply
FredBeck
Posts: 77
Joined: Fri Nov 01, 2013 3:07 pm
Location: Paris
Contact:

Function polymorphism

Post by FredBeck » Wed Apr 15, 2015 10:40 am

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.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9567
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Function polymorphism

Post by dunbarx » Thu Apr 16, 2015 1:22 am

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

FredBeck
Posts: 77
Joined: Fri Nov 01, 2013 3:07 pm
Location: Paris
Contact:

Re: Function polymorphism

Post by FredBeck » Thu Apr 16, 2015 8:44 am

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.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9567
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Function polymorphism

Post by dunbarx » Thu Apr 16, 2015 3:16 pm

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

FredBeck
Posts: 77
Joined: Fri Nov 01, 2013 3:07 pm
Location: Paris
Contact:

Re: Function polymorphism

Post by FredBeck » Fri Apr 17, 2015 9:00 am

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.

Post Reply

Return to “Converting to LiveCode”