Dispatch vs Libraries

Todd Geist todd at geistinteractive.com
Sun Nov 27 09:42:04 EST 2011


Hello,

I am experimenting with a couple of approaches to something and I am
curious in other opinions on it.

I am using behaviors to encapsulate a bunch of code to access web services.
 I create an "instance" of this object by creating a new button on a
utility card and set a few custom properties. So I have a button for an
Endpoint on the server.  Then I register each instance button in a global
Array so I can reach it from anywhere.  So the code to access it looks like
this:

   dispatch "SaveData" to Services["MyContact"] with DataArray

   put the result into ResultArray


I could also do this by writing all the code in the Library Stack and using
namespaces, So the code would look like this.


 put Services_Contacts_SaveData (DataArray) into ResultArray


but in this case I have to rewrite a lot of boilerplate code over an over
and again and it gets harder to maintain.

Another option would be to use the library approach but pass the Service
name as the first parameter like so

put Services_SaveData ("Contacts", DataArray) into ResultArray


Instances of the Service would be stored in an a script Local array.

Currently I am favoring the first approach. Even though it is an extra line
of code I think it reads better, and I place a high importance on
readability.  I also think it is easier to use overrides, extend and
maintain.  I don't know if there is a performance difference, although I
expect if there is any it would be minimal.

Have I missed something? Is there a significant downside to the first
Approach that I have missed?

Thanks

Todd

-- 
Todd Geist
geist interactive
(805) 419-9382



More information about the use-livecode mailing list