Using Properties instead of Params
Our AUT currently runs through a flow of forms and i have a Unit for each form which i consider to be a class and each form has multiple outcomes and each form has multiple functions. I have added params for input on the functions and i use these functions on many other unit so if i was to change the params or remove, it means updating them in all places the functions are called, which i have found to be bad design and not good for maintainability.
I have some experience with OOP as i done it in college however i would like to create properties for each of my forms(Classes) so that i can add and remove them in one place. I will also create a separate function for the properties so that it covers backwards compatibility if new development changes the input and i wont need to go over the calls to the method to update the properties.
I have read up on the ODT however this has now been removed from the product and i then read over the alternative however i found this difficult to understand and it also didn't work when i attempted it for my function.
Instead of the example below i would prefer to have the params as properties and that a new object couldnt be used without them being defined.
example of current code to be changed
function Main() { inputData("1", "2" ); } function inputData(testInput1, testInput2) { Textbox1.SetText(testInput1); Textbox2.SetText(testInput2); }
Yes. Basically, whatever function you'd determine to be your constructor would assign all your properties. It would look like:
function constructorA() { var localObject = {prop1: '', prop2: 0} //Sets up the object with properties and default values localObject.Method1 = function () { Log.Message('Valjean 1: ' + localObject.prop1); } localObject.Method2 = function () { Log.Message('Marius: ' + localObject.prop2); } return localObject; } function Main() { var myObject = new constructorA(); myObject.prop1 = 'Who am I?" myObject.prop2 = 24601; myObject.Method1(); myObject.Method2(); }