hfettig Posted October 7, 2009 Report Share Posted October 7, 2009 Hi folks, I have used LabVOOP before, mainly to implement instrument drivers with base and child classes. Now I am looking into creating my first LabVOOP architecture and I have a few questions about some implementation details regarding the by Value functionality of LabVOOP. Say I have an object called Farm that contains an object called ListOfPigs, which handles an array of Pig objects. Now the Pig class has a method called RecordPiglets(BornAlive, StillBorn, Mummified). In C# I would call that function like this: Farm.Pig[tag].RecordPiglets(7,0,0) I have no problem getting to the Farm.Pig[tag] point in LabVOOP, i.e. extracting the Pig object in question. But if I now run the RecordPiglets method on that object I will have to update the Pig object in the ListOfPigs object, and then update that object in the Farm object. I could do that by creating an UpdateObject for every GetObject method in every class. However, that seems a bit unwieldy. Is there an easier way? Thanks for your help, Heiko Quote Link to comment
Francois Normandin Posted October 7, 2009 Report Share Posted October 7, 2009 I have no problem getting to the Farm.Pig[tag] point in LabVOOP, i.e. extracting the Pig object in question. But if I now run the RecordPiglets method on that object I will have to update the Pig object in the ListOfPigs object, and then update that object in the Farm object. I could do that by creating an UpdateObject for every GetObject method in every class. However, that seems a bit unwieldy. Is there an easier way? Thanks for your help, Heiko Indeed, to preserve dataflow, this is exactly what you have to do. If you have many classes, let's say "pigs", "cows" and "goats", then you should add a layer "animal" from which they all inherit. Your Farm class would contain a list of Animals and you can have only one "Write/Read infants" for the Animal class, provided that all animals have the same "bornalive/stillborn/mummified" properties for the infant counts. If you need to override with a different Read/Write for a particular animal, then you can. But it should let you have only one UpdateObject for the whole animals hierarchy. 1 Quote Link to comment
Daklu Posted October 7, 2009 Report Share Posted October 7, 2009 I could do that by creating an UpdateObject for every GetObject method in every class. However, that seems a bit unwieldy. Is there an easier way? I don't think there's an elegant way to do this with by-val objects given your class hierarchy. By-ref objects would do it--they may not be the best solution for your particular situation though. Quote Link to comment
MikaelH Posted October 7, 2009 Report Share Posted October 7, 2009 Hi I would of cause not even consider by value unless I really needed the highest speed. This is a reference solution: Farm.zip As an initial design I wouldn’t add the complexity of the List object, and have the array of animals direct in the Farm attribute. Cheers, Mikael 1 Quote Link to comment
Aristos Queue Posted October 8, 2009 Report Share Posted October 8, 2009 I would of cause not even consider by value unless I really needed the highest speed. I on the other hand would not even consider a reference solution unless all else failed. My solution: Give your ListOfPigs class a method called UpdateOnePig, which takes an index of a pig and instructions on what to do to that pig. The instructions can come in the form of parameters that you pass into the ListOfPigs' VI or a VI Reference that you call. The block diagram of the UpdateOnePig has an InplaceElementStructure that has an Index and Replace array node on it. Quote Link to comment
MikaelH Posted October 8, 2009 Report Share Posted October 8, 2009 I on the other hand would not even consider a reference solution unless all else failed. I agree that by value should be used where ever it’s applicable. By most of my classes are instrument drivers and there I can’t live without references. Some other classes are Singletons and others uses shared aggregation, and therefore it makes my life easier to use one type for all of them, because if I forget that a particular class is by value I get really strange errors ;-) This is an example of the different looks and feels when using composite aggregation. ByRefByValue.zip Cheers, Mikael 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.