LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I copy an LVOOP method to a sibling class?

[cross-posted to LAVA]

 

I have a situation where I need to duplicate some code in sibling methods. Ideally, I would put this code inside the parent class, but for performance reasons (I don't want to use variants) and a limitation in LabVIEW's edit-time type adaption/propagation, the code must in the child class.

This means that every time I want to change the implementation of my code, I have to duplicate the code in the sibling methods. What I'm looking for is an easy way to copy a method into a sibling. Now, I can sort of do this with a "Save a Copy As" operation, but then I have to manually relink the copy to the sibling classes data types (such as the object/class-private-data, etc.).

Has anyone solved this problem? I'm tempted to try to automate this using either scripting or by modifying the linker info on disk, as described below:

Copy "ClassA.lvclass:Method.vi" (<MyProject>/ClassA/Method.vi) to "ClassB.lvclass:Method.vi" (<MyProject>/ClassB/Method.vi) on disk. Modify the linker info of "ClassB.lvclass:Method.vi" (<MyProject>/ClassB/Method.vi) on disk, such that every instance of "ClassA.lvclass" in the linker info is replaced by "ClassB.lvclass".

I've got to do this periodically for about 30 sibling classes, so it's starting to make sense to automate this task.

0 Kudos
Message 1 of 4
(3,466 Views)
What I suspect you want is the Delegation pattern. That data that you were thinking needed to be a variant? That's another class hierarchy. The handling of that data can go in the parent class of your primary hierarchy. Anything that needs to be specific to the type of that data is encoded in the other hierarchy.
0 Kudos
Message 2 of 4
(3,451 Views)

You're probably right, although I'd like to avoid having 60 classes vs. the 30 sibling classes that I have now, due to the general pains of working with classes.  As such, having an easy way to copy a method to a sibling is ideal.

0 Kudos
Message 3 of 4
(3,441 Views)
BTW, I've posted a more precise description of my code duplication problem, here.
0 Kudos
Message 4 of 4
(3,432 Views)