LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simple example of child accessing Parent data

Solved!
Go to solution

Hi all,

 

Im trying to explore and make sense of OOP.  Ive been learning as much as i can, but for whatever reason cant seemt to pull parent data to a child class.  Ive set the child to inherit from the parent and created a parent accessor for read and write.  I write data to the parent class and then try to read data in the child class. Is there something im missing? Does anyone have or know a link to a simple example of this?

 

Thank you,

Matt



-Matt
0 Kudos
Message 1 of 9
(5,297 Views)

It sounds like you are doing it properly.  Can you supply some code so we can help you figure out where you went wrong?


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 9
(5,286 Views)

Hi Cruz,

 

Thanks for the help.  Attached is a very simple project.  Maybe you can tell me if im way off base here or not.  If so can you just demonstrate how it should work.

 

 

Thank you,

 

Matt



-Matt
0 Kudos
Message 3 of 9
(5,281 Views)
Solution
Accepted by topic author Wolleee

Ok.  I think you have a misunderstanding of how OOP works here.  The idea with OOP is that you can pass the child object into the parent's methods and it acts on that object anyways.  Your diagram should look like this:


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 9
(5,270 Views)

Hi cruz,

 

So its not so much that i can access the data from the parent? More that i can access the methods and data type? I was playing around and had that vi working, but wasnt sure how useful id find that.  At this moment at least.

 

Matt



-Matt
0 Kudos
Message 5 of 9
(5,264 Views)

matt198717 wrote:  So its not so much that i can access the data from the parent? More that i can access the methods and data type?

That is correct.  That is how it is in all OOP languages (at least the ones I know of).  And LabVIEW uses a value-based OOP.  So the object only updates on the wire.  It is not a reference.

 


matt198717 wrote:  I was playing around and had that vi working, but wasnt sure how useful id find that.  At this moment at least.

Oh, it is EXTREMELY useful.  OOP becomes very powerful when you start looking at reuse and expanding your application.

 

As a quick example that I did in the last couple of years: I had an application that was to read torque and angle from an instrument.  Later in the project, I had to expand it to use another, very similar but not quite, instrument.  So I made a child class and override only the methods that needed changed.  Any additional information I need for that new instrument was in the child class.  But all of that code for accessing data in the parent did not have to change or be duplicated.

 

OOP takes a little bit to get used to.  But once you do, you will find it makes programming things so much easier for complex programs.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 9
(5,249 Views)
I've been reading and I can totally agree with you. I'm writing a larger application that will be the means of control and communication between two devices. I have a set of tests that it will be running but I know there will be additional tests added to the application. So I'm thinking oop is probably the way to go. May take some getting used to but I think it'll pay off in the long run. Any advise as to the architecture I should choose? I've been looking into the jki Smo. It seems useful for a beginner in oop

As usual thanks for the help.


-Matt
0 Kudos
Message 7 of 9
(5,217 Views)

@matt198717 wrote:
Any advise as to the architecture I should choose? I've been looking into the jki Smo. It seems useful for a beginner in oop

I have not had a chance to look at the JKI State Machine Objects.  But coming from JKI, I am certain it is well put together.  But what I would recommend is reading up on OOP in general.  I highly recommend The Object-Oriented Thought Process.  It has no clue about LabVIEW (not even mentioned), but it is excellent in helping you figure out how objects in general work.  It is a easy read and has a lot of good information.  Once you get your head around that, make up an UML diagram (you will learn about those in that book).  OOP requires some forethought and UML diagrams are a great way to organize how things will work before writing any code.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 9
(5,191 Views)

Thanks for tip.  Ive read a few documents for using OOP in labview and ive actually looked through the online course in labveiw, but still i think its going to take a while and i think i need to get up to speed as fast as i can.  Either way i think its going to be a very useful tool.

 

Thanks,

 

Matt



-Matt
0 Kudos
Message 9 of 9
(5,109 Views)