G#

cancel
Showing results for 
Search instead for 
Did you mean: 

Parent Class Property Get/Set Override

Using Labview 2012

Windows 8

Say we have Class G with the property of P

has methods GetP and SetP

and we have class G_Child child of Class G

when you want to override the Methods GetP and SetP to use with G_Child class

by G# IDE > Create Methods... > Overide Method and pick either GetP or SetP of Class G

1) the method is not placed in the properties folder but instead in the main class folder and breaks all of the classes

2) the method does not call Parent Class' GetP or SetP method instead gives you an unbundle node with the own properties of Class G_Child but places and indicator of Property P as it should do but it is not wired to anything

any suggestions or comments please

0 Kudos
Message 1 of 4
(8,187 Views)

Hi Mike,

You are correct that overriding the methods break the code, although the properties show up as methods they are a bit special. The solution is to create a new property with the same name in the child class and it'll automatically override the parents. (I just verified it in code)

What you're seeing is the default template of a attribute reading vi. You bring up a good point that overriding properties should be possible in the Create methods menu, i'll bring it forward.

/Albert

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 2 of 4
(5,570 Views)

Hi Albert,

Thank you for your reply and your solution to my problem helps, well kind of, the problem is when i create a new property with the same name the resulting vi has the child class' GetAttributes method which does not give you the Property you actually want because you are trying to get/set an attribute of a parent class where it might not be an immediate parent.

Having said that; I have a question and a suggestion

why does GetAttributes method of a child class bring attributes inherited from parent(s)

in my opinion when you create a public property with read and write methods created alongside all child classes down in the hiarchy should automatically have already overridden methods even if the methods are not going to be modified in the child class. Actually that should go for all overrideable methods otherwise you end up looking for methods in parent classes to place on the block diagram. Please allow me to express this in an other way

say in a text based language you do this,

Class_A = class

  P = property

  GetP = method

Class_B = class of Class_A

  T = property

  GetT = method

Class_A.GetP

  {

    ...Code to get P

  }

Class_B.GetT

  {

    ...Code to get T

  }

<Main Code>

  Create A = Class_A

   Create B = Class_B

  A.GetP  // this is allowed in Labview

   B.GetT  // this is allowed in Labview

   B.GetP // this is not allowed in Labview until you override it eventhough you don't need to modify it

   B.(A).GetP  // you need to use exactly the same method of the parent class definining the method unless you override it

<end>

this is a big problem if you have several generations of classes with lots of methods and you need to call a method you actually inherit via class hiarchy but don't actually know where it is declared or even where it is overridden last.

what do you think guys?

0 Kudos
Message 3 of 4
(5,570 Views)

Hi Mike,

It is a rather uncommon situation to override the properties, but in the property vi (according to previous post), you can replace the Get Attributes vi to the parents and thus override it. From a design pattern perspective it's better to use the parents property, although you can access the attribute directly.

You can also create the properties manually by:

1. New Property definition folder (this'll be the properties name), the wizard collects these under the virtual folder Properties, but it's not needed.

2. Create Get/Set vi's from the Dynamic dispatch template, the vi's must have the same name as the folder. (If folder is Prop, files must be SetProp.vi and GetProp.vi)

3. Profit

The idea of automatically creating functions with only a Call parent when creating a child is an interesting one, i'll pass it on. I also like the idea of being able to get/set properties of parent class directly, but i dont know if that's possible.

Usually you want to build the program by placing functions from the 'Root' class, as you'll lock yourself into a specific class otherwise. As a result we often have "dummy" functions in the root which not all children need/use.

/Albert

AddQ

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 4
(5,570 Views)