Jump to content

OOP: inheritance with by-reference


Recommended Posts

I started using LabVIEW 2009 a few weeks ago. I developed most of my systems following the paradigm of object orientation. For this, I always used the GOOP Wizard tool available on the NI website. With the launch of the new version of LabVIEW, I decided to do some tests to evaluate the new feature of object orientation. In the GOOP framework each object is a reference, which simplifies parameter passing by reference. This is done transparently by the framework and the developer does not need to worry about the details.

After analyzing the LabVIEW 2009 OO framework, I realized that passing parameters by reference is more laborious. However, after several searches on the NI website and Google, I found some tricks that can be used to work with OO by ref. I read some comments posted in LAVA forum. Then, I implemented a pattern suggested by Jim Kring: creating an attribute in the class to store a reference (DVR) for all other attributes. The first tests were successful. However, I started having problems to implement inheritance. The following example ilustrates the problem.

The "Parent" class has the following structure:

- active: boolean

- priority: int32

- randomValue: double

+ run()

The "Child" class inherits from "Parent" and has the structure shown below:

- name: string

+ run()

In LabVIEW, I created a type (DataMembers.ctl) with the attributes of each class. The type (DataMembers.ctl) of Child class references the type of the Parent class. In the private data of each class ("Class Private Data"), I created just one reference (DVR) for the attributes (type DataMembers.ctl). The private data structure of each class can be seen below:

Parent.ctl:

- mySelf: DVR (type DataMembers.ctl of Parent class)

Child.ctl:

-mySelf: DVR (type DataMembers.ctl of Child class)

DataMembers.ctl (Parent class):

- active: boolean

- priority: int32

- randomValue: double

DataMembers.ctl (Child class):

- active: boolean

- priority: int32

- randomValue: double

- name: string

The method run of Child class invokes the method run of the Parent class. In the method run of Parent class, the attribute "randomValue" is updated. In the method run of Child class, the attribute "name" is updated. However, there is a problem in this pattern that I implemented: the Child class stores two references (DVR) due to inheritance. When a Parent class method is invoked, the attributes are updated using the reference of Parent class (attribute "mySelf"). On the other side, when a Child class method is invoked, the attributes are updated using the reference of Child class.

What can I do to solve this problem?

Thanks in advice.

Link to comment

Cross post.

You should announce cross posts to avoid having people do unnecessary work.

I don't have a definite answer for you (I don't have LV in front of me at the moment, I didn't really understand your problem and I'm not too familiar with this design anyway), but there are a couple of things which come to mind:

  1. Based on your description, both classes have the parent's data. Why is that? The inheritance should automatically take care of adding the parent's data to a child object.
  2. I have a feeling that this may also be the source of your problem - when you call the method on the child class, you should then also use the primitive which calls the parent implementation and then that method will be in charge of taking care of the parent's data.
  3. LV programmers manage a lot better if they have actual code to play with. I suggest you zip your project and upload it.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.