OOP in Rev...

viktoras didziulis viktoras at ekoinf.net
Wed Mar 19 08:25:06 EDT 2008


I would like to define a class, an object (the both with their 
properties) and methods that are not a part of graphical user interface 
or Revolution engine...

Let's say I need an object "City" having properties: minLatitude, 
maxLatitude, minLongitude, maxLongitude, area, populationSize, 
growthRate, dateFounded, currentDate so it can be handled using specific 
handlers and functions (e.g. its methods). Or, well, it would be more 
correct to start with creation of a class "City" or "templateCity" and 
then use it to create new "city" objects (NewYork, Paris, etc...) that 
can be processed by their functions like "populationGrowth(Paris, 
start_year, end_year)" and so on...

The three approaches that I can imagine are somehow inter-tangled: (1) 
creating an object as a custom property set of a stack or (2) creating 
it as an array or (3) creating it as an invisible control with custom 
properties. But all these have their drawbacks.

 The (1) and (3) approach allows attaching handlers to custom properties 
and allows accessing object (e.g. a custom property set) properties 
using both an array notation (somehow an equivalent to an array-like 
behavior of objects in javascript) and in a way consistent with handling 
of properties in Rev e.g. "set the .. of .. to ..." or "get .. the .. of 
...". Unfortunately (1) allows only a single object to be active and 
thus accessible. The (3) is a dirty one, because object is created using 
empty controls with their own additional properties and methods. The (2) 
looks promising, one can create a class, write a constructor function 
that would create new objects from the class, etc... But it lacks 
consistency with the existing OOP style in Rev - e.g. you can not get or 
set an element of an array using "get the <element/property> of 
<array/object>" or "set the <element/property> of <array/object> to 
<value>". Besides you can not use getProp or setProp handlers with 
array's elements.

Did anyone try doing something like this kind of OOP in Rev? I would 
appreciate if you can share your thoughts, warnings, tricks and 
approaches :-). I am not looking for a complex C++ like style of OOP in 
Rev. Anything simpler like the OOP model of javascript would be OK. In 
general, I think, it would be nice if one could treat and access 
Revolution arrays as objects with custom properties, with all the 
getProp, setProp and templateObject stuff... Or is it possible somehow? 
If not, is this already posted to QC as an enhancement request - I would 
vote for it? Otherwise going to post it there myself...

All the best!
Viktoras




More information about the use-livecode mailing list