what is needed ...
Trevor DeVore
lists at mangomultimedia.com
Mon May 23 17:21:22 EDT 2005
On May 23, 2005, at 4:00 PM, Marielle Lange wrote:
> I am curious to know. I came across the notion of generic programming
> today. Are the ideas present in the script above something close to
> generic programming?
> "Generic programming is about generalizing software components so that
> they can be easily reused in a wide variety of situations. In C++,
> class and function templates are particularly effective mechanisms for
> generic programming because they make the generalization possible
> without sacrificing efficiency".
Not exactly. In the examples above it looks like you are assigning the
script of the object you want the behavior to apply to. This means
that you will duplicate the script every time you want a certain object
to have that behavior. If the script which provides the desired
behavior were to ever change then you would have to update it in all of
the objects that use it. This means your project is larger because
code is being duplicated and it is more difficult to update.
If we were to generalize the web url example we would do something like
this in Revolution in order to make a generic component (very rough):
==== libBehavior.rev - stack script (start using) ====
on mouseUp
if the uLibBehavior["behavior"] of the target <> empty then
libBehv_process
end if
pass mouseUp
end mouseUp
on libBehv_process
switch the uLibBehavior["behavior"] of the target
case "gotoURL"
revGoURL the uLibBehavior["URL"] of the target
break
end switch
end libBehv_process
Now once you have libBehavior.rev put in use you can set custom
properties of a button, image, etc. to control the behavior. For
example:
set the uLibBehavior["behavior"] of button "MyButton" to "gotoURL"
set the uLibBehavior["URL"] of button "MyButton" to
"http://www.runrev.com"
Now when the user clicks on the button the url would be launched using
revGoURL. To make life easy for someone just getting started with Rev
you could create a little plugin that is a palette that would let you
drag and drop the gotoURL behavior on an object. When the gotoURL
behavior was dropped on an object the plugin would just set the custom
properties of the object as needed and libBehavior.rev would process
the mouseUp event appropriately.
--
Trevor DeVore
Blue Mango Multimedia
trevor at mangomultimedia.com
More information about the education-revolution
mailing list