I use getter/setters all the time - mainly for handling flags (boolean process 
variables). I do the following:


MyFlagMethod
===============
c_boolean($0)
c_boolean($1;fMyFlag)

If(count parameters >= 1)
        fMyFlag := $1
Else
        $0 := fMyFlag
End if


The reason I do this for flags is because I can put my comments that describe 
the usage in one place instead of spread out all over the code everywhere they 
are used (there are few things more frustrating than trying to track down how 
and why process variables are used.) The code is intuitively readable if you 
name the method well. For example, I may need a flag to tell me the current 
context, e.g., IsCalledFromInputForm. In use it looks like this:

IsCalledFromInputForm(True)
...
If (IsCalledFromInputForm)
   `do something
Endif
...
IsCalledFromInputForm(False)


And the getter/setter is so simple that having 2 methods to do the same thing 
ends up being more complex. It also has the advantage of guaranteeing that the 
boolean variable is always defined so you don’t get runtime errors. 

------------------------------------------------
Richard Wright
DataDomain
[email protected]
————————————————————————

> Date: Mon, 9 Jan 2017 11:47:01 +1100
> From: Wayne Stewart <[email protected]>
> 
> Hi,
> 
> With all the recent object stuff, I notice most people are using either
> Cannon's excellent OBJ module or similar.
> 
> I have extended it so I have one routine do both tasks, I like this as it
> means I only have one method to remember and not two.  There is obviously
> some overhead copying the variable into $0 but I've never seen any impact
> from this.  At least not with the variables I've used.
> 
> Does anyone else do this?
> 
> If you don't, why not?
> 
> Eg (based on Cannon's module):
> 
> C_OBJECT($AnObject_o)
> C_TIME($WhenStarted_h;$WhenFinished_h)
> 
> $AnObject_o:=OBJ_Create
> OBJ_Set_Time ($AnObject_o;"Start";Current time)
> $WhenStarted_h:=OBJ_Get_Time ($AnObject_o;"Start")
> 
> FO_Time ($AnObject_o;"Finished";Current time)
> $WhenFinished_h:=FO_Time ($AnObject_o;"Finished")
> 
> Internally FO_Time does this:
> 
> C_OBJECT($1;$Object_o)
> C_TEXT($2;$Key_t)  //Can use dot notation
> C_TIME($3;$Value_h;$0)
> 
> $Object_o:=$1
> $Key_t:=$2
> 
> If (Count parameters=3)
>  $Value_h:=$3
>  OBJ_Set_Time ($Object_o;$Key_t;$Value_h)
> Else
>  $Value_h:=OBJ_Get_Time ($Object_o;$Key_t)
> End if
> 
> $0:=$Value_h  //  Always return a value, 4D doesn't mind if you don't
> receive it




**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[email protected]
**********************************************************************

Reply via email to