03-17-2016 06:26 PM
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
Solved! Go to Solution.
03-17-2016 06:40 PM
It sounds like you are doing it properly. Can you supply some code so we can help you figure out where you went wrong?
03-17-2016 06:44 PM
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
03-17-2016 07:16 PM - edited 03-17-2016 07:17 PM
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:
03-17-2016 07:19 PM
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
03-17-2016 07:26 PM
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.
03-17-2016 09:26 PM
03-18-2016 04:55 AM
@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.
03-18-2016 11:47 AM
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