12-09-2023 12:56 AM
In object-oriented programming, when you have a class hierarchy like "Square" inheriting from "Rectangle," Is it better to use dynamic dispatch (polymorphism) or static dispatch (method hiding or shadowing) for the "WriteHeight" and "WriteWidth" functions?
Solved! Go to Solution.
12-09-2023 06:50 AM
Hi Fresenius,
If you want to allow (or force) redefinition of these methods in the child class, you must use dynamic dispatch (for both base and child methods). Static dispatch is used when a method should not be redefined by a child class.
Also, the concept of method hiding like in java does not exist with LabVIEW Objects.
If, in a child class, you try to name a static method the same as a static method in one of its ancestor classes, your method will be broken with the error: "This VI attempts to override a static VI in an ancestor class". So you'll either have to make the methods dynamic or choose another name for the method in the child class.
Also, your example is a bit particular because mathematically speaking, the width and height of a "Square" should not be set independently. So you would have to override methods "WriteWidth" and "WriteHeight" to make them write both width and height to the same value.
Regards,
Raphaël.