I was playing with OOP/ABL in v10.1A, when I noticed my class unnecessarily growing because of repeatedly creating set/get methods. Some OOP language I've seen has one liner setter/getter. I thought there should be a way of having "one-liner" (well, not really) as well for 10.1A. :-)
So here goes..enhance if you must..
/* ===================== here's the meat!!! includes/SetGet.i 1 - variable name 2 - data type ===================== */ DEFINE PROTECTED VARIABLE {1} AS "{2}" NO-UNDO. METHOD PUBLIC "{2}" get{1}(): RETURN {1}. END METHOD. METHOD PUBLIC VOID set{1}(p{1} AS "{2}"): ASSIGN {1} = p{1}. END METHOD.
now attach this include to every class that requires a setter/getter. in this sample MyName is a variable of type CHARACTER. This class will have getMyName and setMyName methods. On set, variable pMyName is created.
CLASS Name: {includes/SetGet.i MyName CHAR} END CLASS.
instantiate the class..
DEF VAR MyName AS CLASS Name. MyName = NEW Name(). MyName:setMyName('Joey'). MESSAGE MyName:getMyName() VIEW-AS ALERT-BOX INFO BUTTONS OK.
ty!!!
Comments
Or, go to 10.1B where there
Or, go to 10.1B where there are properties.
define public property x as character no-undo. get. set.
I'd much rather do that than a mess of includes.