Currently I'm busy with GOOP and I came across the following problem.
I have a validator class. The purpose of this class is to validate data. The validator class as a number of childrens...
Validate IP address
Validate string length
Validate inRange number
Validate Alpha
The main, validator, class has a function called "valid?" This function has 3 inputs and 3 outputs
Inputs:
- Object
- The data that must be validated
- Error
Output:
- Object
- Valid?
- Error
The children classes must inherit this function and overwrite it. Now the problem is is that each of the above validators have a different datatype which must be validated....
Validate IP address has a string as input
Validate string length has a string as input
Validate inRange number has a number as input
Validate Alpha has a string as input
Now you might see the problem. To get the children to inherit the function from the main, validator, class the connector pane must be the same as of the datatypes... This means that I have to choose in my main function to use a string or a number as input... This is something that I don't want... I want to be able to select a datatype called "yet unknown datatype" in my main "valid?" function in the main, validator, class. So that I can use any datatype input in my children that is suitable for that implementation.
My idea is thus to create a new kind of datatype which sort of represents "any kind of datatype known to labview" which can be used in functions of a main class that are inherited by its children, which are all using a different input datatype.
ps. Now you could maybe suggest why not use a variant datatype? Yes this is possible but the problem is;
- I would have to cast the data back
- It isn't very neat programming, the variant solution is in my opinion more a kind of hack to make the code work.
pss. Yes but if you would do this... then...
- Yes there are proberbly a few more work arounds thinkable, such as creating two "Valid" VI's one inherited (Valid?), one unique of the child (_Valid?), but these are in my opinion still workarounds and do not really provide the functionality that is needed. Which is pretty common in OOP languages.
psss. if anyone knows a better title for this described idea let me know it!