Function polymorphism
Posted: 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.
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.