From: Eric D. <eri...@bi...> - 2011-12-28 16:31:53
|
As an ex-mainframe person who has been using REXX extensively for over 20 years, and using ooRexx procedurally for the last 5. I am trying to update myself to develop code using the OO techniques. I have read the documentation and I believe I understand the basics of methods, but I am currently stuck using attributes - specifically how to validate the values an attribute can have. I can't seem to find simple examples of creating methods and validating. Apologies if this is a basic question that I should have referred elsewhere Eric Davidson |
From: Oliver S. <oli...@si...> - 2011-12-29 23:48:56
|
Hi Eric, Don't know if I can help, but I agree that using attributes is not quite as clear in the documentation as it might be (although there's an example of validation on page 82 of the ooRexx Reference). Now I don't claim to be an expert on attributes, but I do know that OO languages/software have many ways of implementing the attribute concept. The ooRexx approach, once you get used to it, is imho rather nice. The following code aims to provide some examples of using attributes - both defining them in a class called "MainlyAttributes" and getting/setting then from outside the class. Each of the three attributes in the class is defined slightly differently to indicate the range of options available. Hope this helps. /* Check out Attributes A class with three attributes - x, y, and z, each specified differently: x is fully spec'd using the ::attribute directive for both get and set. Note the "set" code provided with the ::attribute directive. This code constrains the value to be a numeric whole positive number and is taken from the ooRexx Reference (page 82). y uses the ::attribute statement for gets only; the set is provided as a specific method called "y=". This method checks for numeric and returns either .true or .false. Note that the returned value must be checked using the "result" special variable. If ,false is returned, the value of y is set to the string "Not Set". z uses a single ::attribute directive with default get/set bevavior. */ i = .MainlyAttributes~new say; say "-----------------Attributes Test----------------------------" -- Get initial values of all three attributes: say "Initial values of attributes assigned in the 'init' method:" say "x=" i~x " y=" i~y " z=" i~z say; say "Set x to 123 with the statement 'i~x = 123'." i~x = 123 say "x is now:" i~x say; say "Invoke a method that 'gets' all three attributes:" i~getAllThree say; say "Set y to an invalid value ..." say "Invalid: i~y='abc'" i~y='abc' say "Result =" result say "... and now to a valid value:" say "Valid: i~y=100" i~y=100 say "Result =" result say; say "Set z to a different value using i~z='xyz'" i~z='xyz' say "z =" i~z say; say "Set x to a valid numeric value using i~x=123" i~x = 123; say "i~x =" i~x say; say "Set x to a non-numeric value. This will raise an error and exit." say "But it's the last example in this program, so an exit here is OK." i~x = "abc" -- ---------------------------------------------------------------------------- - ::class MainlyAttributes ::attribute x get ::attribute x set expose x use arg value -- Prevent x having a value that is not a whole number by throwing an error -- and exiting if x is assigned a bad value: if datatype(value, "Whole") = .false | value < 0 then raise syntax 93.906 array ("x", value) x = value return 1 ::attribute y get ::attribute z ::method init expose x y z x = 0 y = "" z = "abc" ::method getAllThree expose x y z say "x =" x say "y =" y say "z =" z ::method "y=" -- equivalent to ::attribute y set expose y use arg a if a~datatype("N") then do y = a return .true end y = "" return .false -- ---------------------------------------------------------------------------- - _____ From: Eric Davidson [mailto:eri...@bi...] Sent: 28 December 2011 16:32 To: oor...@li... Subject: [Oorexx-users] ::attribute validation As an ex-mainframe person who has been using REXX extensively for over 20 years, and using ooRexx procedurally for the last 5. I am trying to update myself to develop code using the OO techniques. I have read the documentation and I believe I understand the basics of methods, but I am currently stuck using attributes - specifically how to validate the values an attribute can have. I can't seem to find simple examples of creating methods and validating. Apologies if this is a basic question that I should have referred elsewhere Eric Davidson |
From: Eric D. <eri...@bi...> - 2011-12-30 14:45:34
|
Many thanks Oliver. I had found the sample in the manual, but has confused myself when trying to transfer it to my own code. I have now been able to create some sample code of my own using the information you have provided and I believe I understand more (but not enough) of how the OO environment works Eric On 29 December 2011 23:48, Oliver Sims <oli...@si...>wrote: > ** > Hi Eric, > > Don't know if I can help, but I agree that using attributes is not quite > as clear in the documentation as it might be (although there's an example > of validation on page 82 of the ooRexx Reference). Now I don't claim to > be an expert on attributes, but I do know that OO languages/software have > many ways of implementing the attribute concept. The ooRexx approach, once > you get used to it, is imho rather nice. > > The following code aims to provide some examples of using attributes - > both defining them in a class called "MainlyAttributes" and getting/setting > then from outside the class. > Each of the three attributes in the class is defined slightly differently > to indicate the range of options available. Hope this helps. > > > /* Check out Attributes > > A class with three attributes - x, y, and z, each specified differently: > x is fully spec'd using the ::attribute directive for both get and set. > Note the "set" code provided with the ::attribute directive. This code > constrains the value to be a numeric whole positive number and is > taken > from the ooRexx Reference (page 82). > y uses the ::attribute statement for gets only; the set is provided as a > specific method called "y=". This method checks for numeric and > returns > either .true or .false. Note that the returned value must be checked > using > the "result" special variable. If ,false is returned, the value of y > is set > to the string "Not Set". > z uses a single ::attribute directive with default get/set bevavior. > > */ > > i = .MainlyAttributes~new > > say; say "-----------------Attributes Test----------------------------" > > -- Get initial values of all three attributes: > say "Initial values of attributes assigned in the 'init' method:" > say "x=" i~x " y=" i~y " z=" i~z > > say; say "Set x to 123 with the statement 'i~x = 123'." > i~x = 123 > say "x is now:" i~x > > say; say "Invoke a method that 'gets' all three attributes:" > i~getAllThree > > say; say "Set y to an invalid value ..." > say "Invalid: i~y='abc'" > i~y='abc' > say "Result =" result > say "... and now to a valid value:" > say "Valid: i~y=100" > i~y=100 > say "Result =" result > > say; say "Set z to a different value using i~z='xyz'" > i~z='xyz' > say "z =" i~z > > say; say "Set x to a valid numeric value using i~x=123" > i~x = 123; > say "i~x =" i~x > > say; say "Set x to a non-numeric value. This will raise an error and exit." > say "But it's the last example in this program, so an exit here is OK." > i~x = "abc" > > > -- > ----------------------------------------------------------------------------- > ::class MainlyAttributes > > ::attribute x get > ::attribute x set > expose x > use arg value > -- Prevent x having a value that is not a whole number by throwing an > error > -- and exiting if x is assigned a bad value: > if datatype(value, "Whole") = .false | value < 0 then > raise syntax 93.906 array ("x", value) > x = value > return 1 > > ::attribute y get > > ::attribute z > > ::method init > expose x y z > x = 0 > y = "" > z = "abc" > > ::method getAllThree > expose x y z > say "x =" x > say "y =" y > say "z =" z > > ::method "y=" -- equivalent to ::attribute y set > expose y > use arg a > if a~datatype("N") then do > y = a > return .true > end > y = "" > return .false > > -- > ----------------------------------------------------------------------------- > > > > > ------------------------------ > *From:* Eric Davidson [mailto:eri...@bi...] > *Sent:* 28 December 2011 16:32 > *To:* oor...@li... > *Subject:* [Oorexx-users] ::attribute validation > > As an ex-mainframe person who has been using REXX extensively for over 20 > years, and using ooRexx procedurally for the last 5. I am trying to update > myself to develop code using the OO techniques. > > I have read the documentation and I believe I understand the basics of > methods, but I am currently stuck using attributes - specifically how to > validate the values an attribute can have. > > I can't seem to find simple examples of creating methods and validating. > > Apologies if this is a basic question that I should have referred elsewhere > > Eric Davidson > |
From: Mark M. <mie...@gm...> - 2011-12-30 02:14:30
|
Hi Eric, On Wed, Dec 28, 2011 at 8:31 AM, Eric Davidson <eri...@bi...>wrote: > I have read the documentation and I believe I understand the basics of > methods, but I am currently stuck using attributes - specifically how to > validate the values an attribute can have. > > I can't seem to find simple examples of creating methods and validating. > Oliver's answer should be helpful, but I'm curious as to what you mean by 'validating'? Maybe you could be a little more specific as to what you mean. I guess the main reason I ask, is that ooDialog has the concept of 'data attributes' and also has the validate() method. So I wonder if your question is in relationship to ooDialog, or ooRexx in general? -- Mark Miesfeld |
From: Eric D. <eri...@bi...> - 2011-12-30 15:04:46
|
Mark Yes Olivers help was excellent. To set the scene - I am an IBM mainframe man of some 40 years experience, and an ardent fan of Rexx ever since I first used it in the 80s. Over the last 4 years I have been producing ooRexx code for running various batch processes on Windows Servers, with virtually all the code being procedural. I am trying to update myself and use OO methods where I can, and I am playing with routines that I use in my code and trying to rewrite them. Virtually none of the code uses ooDialog, (though I hope to start using it in some future work). My main challenge is trying to get my mind (ancient as it is) round the OO mindset and terminology but in a practical way with items that are familiar to me, and then I can build on that as necessary. Eric On 30 December 2011 02:14, Mark Miesfeld <mie...@gm...> wrote: > Hi Eric, > On Wed, Dec 28, 2011 at 8:31 AM, Eric Davidson <eri...@bi...>wrote: > >> I have read the documentation and I believe I understand the basics of >> methods, but I am currently stuck using attributes - specifically how to >> validate the values an attribute can have. >> >> I can't seem to find simple examples of creating methods and validating. >> > > > Oliver's answer should be helpful, but I'm curious as to what you mean by > 'validating'? Maybe you could be a little more specific as to what you > mean. > > I guess the main reason I ask, is that ooDialog has the concept of 'data > attributes' and also has the validate() method. So I wonder if your > question is in relationship to ooDialog, or ooRexx in general? > > -- > Mark Miesfeld > > |