LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Fastest way to create child class from parent?

As the subject states, what do you folks find is fastest when creating child classes directly from the parent? (esp. when the parent is in a lvlib) I thought I'd post up and ask because the fastest way I've found to get working takes a few steps.

 

Any suggestions ae appreciatized!

 

-pat

0 Kudos
Message 1 of 9
(7,759 Views)

create new, set inheritance, done.

 

I'm probalbly missing something so please expnad on what you are doing.

 

Curious,

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 2 of 9
(7,757 Views)

Thanks for the quick response Ben!

 

Yea, I apologize, in your response I realize my OP was more than vague haha (it hapens when you get used to your own way of doing things I guess huh)- I'm trying to create a child from a parent so that it has all of the methods that the parent has.

 

In order to do so I currently have to open and close LV a few times during my current process so that vi's in memory dont get mixed up- Currently I save a copy of the parent class in a sub dir of where it is saved, close out of LV, open the new 'copy of parent.lvclass', save as>>rename 'child class.lvclass', close LV, and open up the project to 'add file', then right click>>properties>>inheritance.

 

Is this the only way to do this?

 

Thanks again!

-pat

 

p.s. I'm tempted to steal your cell phone sig, hope you dont mind haha good stuff!

0 Kudos
Message 3 of 9
(7,747 Views)

I don't quite understand why you are doing this. When you create a child class, unless you changed the method accesses, it inherits all the parents methods, i.e., you can call it from the child class.

Message 4 of 9
(7,739 Views)

You can try this:

 

http://lavag.org/topic/15390-create-child-class-project-tool/


___________________
Try to take over the world!
Message 5 of 9
(7,718 Views)

1. Create a class

2. Go to class property

3. Set inheritance

0 Kudos
Message 6 of 9
(4,899 Views)

@plyons.gks wrote:
-snip-
I'm trying to create a child from a parent so that it has all of the methods that the parent has.

-snip-

 

Thanks again!

-pat


I may be reading in between the lines here, but this sounds like bad practise if the parent isn't essentially an "Abstract" class.

 

A lot of people are the opinion that inheriting from a class with concrete implementations of methods to override those concrete methods can be tricky. Typically, one would create an intermediate class with "abstract" methods which children can override.  There ARE cases where it's legitimate though.

 

What I do when I want to create a child of an abstract class is I perform a "Save As" on the parent, choose where to save it and then change the inheritance manually. That way it has blank placeholders for all the methods defined int he parent. Any I don't want to override, I just remove from the class definition and delete on disk.

0 Kudos
Message 7 of 9
(4,880 Views)

Well, I didn't want to post yesterday since this was an 8-year necro, but if it's becoming an actual discussion again, what's wrong with simply creating a new class, setting inheritance via the Properties page, and then choosing New > VI for Override from the right click menu (on the class) and then holding shift whilst selecting the VIs to override (all of them, in the example described).

It seems likely that the key point is (was)? as Intaris is pointing at here:


@Intaris wrote:

... inheriting from a class with concrete implementations of methods to override those concrete methods can be tricky. Typically, one would create an intermediate class with "abstract" methods which children can override.  There ARE cases where it's legitimate though.

If the class to be copied has concrete implementations, and you want to make small edits to that code but still basically keep most of the implementation, you'd be better in my opinion creating a subVI in the relevant methods that was dynamic dispatch and using the Template pattern (Implementation in LabVIEW by Elijah Kerrywikirefactoring.guru) to allow a new child of your existing class to only change that bit (perhaps providing the concrete implementation in the existing class (i.e. via selection and Create SubVI) and then just overriding and not using the Call Parent Node).

 

If you have concrete implementations but you don't want to copy the implementation, but you'd rather have a new "sibling-like" class with an alternative (completely different) implementation, what you need is a parent class (ideally abstract, as Intaris mentioned). To create one of these more easily in LabVIEW, take a look at Sam Taggart's Class Refactoring Tools, which include a right click option to create an interface class (the tools predate 2020, so this will as far as I know still be a class, not an interface).


GCentral
0 Kudos
Message 8 of 9
(4,871 Views)

@cbutcher wrote:

Well, I didn't want to post yesterday since this was an 8-year necro


Ah. So it is. Didn't notice that. Otherwise I wouldn't have bothered answering.

0 Kudos
Message 9 of 9
(4,838 Views)