Jim Kring Posted February 19, 2009 Report Share Posted February 19, 2009 [cross-posted to ni.com] 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. Quote Link to comment
mje Posted February 19, 2009 Report Share Posted February 19, 2009 Let me make sure I understand your situation: you have multiple sibling classes that define a method which contains identical code? As you said, ideally this should go into the parent class, but if that's not a possibility, perhaps re-thinking the inheritance chain might do the trick? It seems to me that having identical siblings breaks one of the fundamental paradigms of object oriented design, you're essentially implementing an interface identically in all classes... Quote Link to comment
ragglefrock Posted February 19, 2009 Report Share Posted February 19, 2009 QUOTE (Jim Kring @ Feb 18 2009, 12:30 PM) [cross-posted to ni.com]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. Sorry about avoiding answering your actual question, but you might also consider a Delegation Pattern, described as such in the link: "To have two independent classes share common functionality without putting that functionality into a common parent class." Quote Link to comment
Jim Kring Posted February 19, 2009 Author Report Share Posted February 19, 2009 Thanks for your responses. Here's some more background: Each sibling class has some data that needs to be obtained as a flattened string in little-endian byte order. How can I put this code snippet in only one VI without the use of variants? Quote Link to comment
ragglefrock Posted February 19, 2009 Report Share Posted February 19, 2009 QUOTE (Jim Kring @ Feb 18 2009, 01:41 PM) Thanks for your responses. Here's some more background:Each sibling class has some data that needs to be obtained as a flattened string in little-endian byte order. How can I put this code snippet in only one VI without the use of variants? For the scripting method, the VIs located here look promising if you can figure out how to use them correctly without seeing their block diagram, which obviously could be tricky. But from their names they seem to do a lot of the operations you seem to be trying to do. <LabVIEW>\resource\Framework\Providers\LVClassLibrary They seem to be the project providers that handle actions from operating on classes in a LV Project. For instance, I see one VI in the New Override folder called CLSUIP_ReplaceDynDispatchCtls.vi that seems like it could be useful. But without seeing the BDs it's hard to tell exactly... I'd personally prefer a more code-oriented approach if I could devise one. For instance, you could put the Flatten to String method in the parent, but the data isn't a variant, but a generic Data class. Every child class contains a child class of the generic Data class that contains the child-specific data. Then you're not dealing with variants. The difficulty would be that you would need to create a unique Data class for every child object and go through the trouble of creating accessors, too. Quote Link to comment
Jan Klasson Posted February 20, 2009 Report Share Posted February 20, 2009 Hi, I have a solution which is to use the GOOP Development Suite for your native class. Sorry about the plug... There is a feature called "Clone VI" which allows you to clone a VI a and select a new class (and VI name). The new VI will be properly linked to data types of the new class. The icon will also be fixed of course. Right click on the VI and select: GOOP->Clone VI... Try it: http://www.endevo.se/index.php/en/Products_Info/Trial.html Community Edition is free. Jan Endevo, part of Flander Group www.endevo.se Quote Link to comment
MikaelH Posted February 20, 2009 Report Share Posted February 20, 2009 GOOD NEWS this feature works on normal LVClasses made without the GDS tool. (Of cause I can't understand how you can work with classes without this tool ;-) The function also supports cloning one base class method to several child classes at once. So install the GDS tool, and just right click on the VI, and select GOOP->Clone VI... Cheers, Mikael Quote Link to comment
Jim Kring Posted February 20, 2009 Author Report Share Posted February 20, 2009 QUOTE (Jan Klasson @ Feb 19 2009, 01:41 AM) I have a solution which is to use the GOOP Development Suite for your native class. Sorry about the plug...There is a feature called "Clone VI" which allows you to clone a VI a and select a new class (and VI name). The new VI will be properly linked to data types of the new class. The icon will also be fixed of course. Right click on the VI and select: GOOP->Clone VI... Try it: http://www.endevo.se/index.php/en/Products_Info/Trial.html Community Edition is free. QUOTE (MikaelH @ Feb 19 2009, 05:02 AM) GOOD NEWS this feature works on normal LVClasses made without the GDS tool. (Of cause I can't understand how you can work with classes without this tool ;-) The function also supports cloning one base class method to several child classes at once. So install the GDS tool, and just right click on the VI, and select GOOP->Clone VI... Hi Jan and Mikael, Thanks for the tip. I actually did already look in the GDS tool (which I have installed and use, regularly) and was not sure what "Clone VI" did. I tried it, but it doesn't work for me. Here are the problems: 1) My sibling class already has an instance of the method that I'm trying to clone. The GDS "Clone VI" dialog will not permit me to make a clone that overwrites/replaces an existing method. 2) The GDS "Clone VI" dialog only permits sending the new clone to a single class. I want to send it to about 30 sibling classes. Ideally, I don't want to have to do a "Clone VI" operation 30 times. Thanks, -Jim Quote Link to comment
MikaelH Posted February 20, 2009 Report Share Posted February 20, 2009 QUOTE (Jim Kring @ Feb 20 2009, 08:26 AM) 1) My sibling class already has an instance of the method that I'm trying to clone. The GDS "Clone VI" dialog will not permit me to make a clone that overwrites/replaces an existing method. I can of cause add a checkbox that allows the tool to delete any existing method before, but that's a bit scary. If I add an automated backup feature of the deleted/removed method then it would be quite safe. We're just about to release a new version and I'll see if I can squeeze this function in. QUOTE (Jim Kring @ Feb 20 2009, 08:26 AM) 2) The GDS "Clone VI" dialog only permits sending the new clone to a single class. I want to send it to about 30 sibling classes. Ideally, I don't want to have to do a "Clone VI" operation 30 times. You can clone a method (from the base class), to one or all siblings, see image below: I haven't added the function of sending a method to several other classes but it's a small task to do that. I can create a beta version for you during the weekend if you are interested? Cheers, Mikael Quote Link to comment
Jim Kring Posted February 20, 2009 Author Report Share Posted February 20, 2009 QUOTE (MikaelH @ Feb 19 2009, 03:49 PM) I can of cause add a checkbox that allows the tool to delete any existing method before, but that's a bit scary.If I add an automated backup feature of the deleted/removed method then it would be quite safe. We're just about to release a new version and I'll see if I can squeeze this function in. You can clone a method (from the base class), to one or all siblings, see image below: I haven't added the function of sending a method to several other classes but it's a small task to do that. I can create a beta version for you during the weekend if you are interested? > I can of cause add a checkbox that allows the tool to delete any existing method before, but that's a bit scary. How about adding an OK/Cancel confirmation dialog letting the user know that pressing OK will overwrite existing files (if that's the case). That wouldn't scare me at all. Plus, I use Subversion and commit my code very frequently > You can clone a method (from the base class), to one or all siblings, see image below: How about adding another option for New VI Owner called "<Clone VI to Selected Sibling Classes>" that populates the bottom list with a list of all the sibling classes? > I can create a beta version for you during the weekend if you are interested? Of course I am Thank you very much, -Jim Quote Link to comment
Jan Klasson Posted February 21, 2009 Report Share Posted February 21, 2009 Mike will include an updated Clone VI in the GDS 3.1 beta we are working on. Also: Update about Endevo tools. www.endevo.se is redirected to www.flander.com. Use this link to download GOOP Development Suite: http://www.flander.com/English/Endevo/Prod...US/Default.aspx Endevo was purchased by Flander in December. We believe it is positive for Endevo; for our OO-UML tools and training effort it is business as usual. Read the press release if you want to know more: http://www.flander.com/English/NewsMedia/N...US/Default.aspx Jan Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.