Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 04/09/2013 in all areas

  1. Here's another Visitor Pattern example that follows the traditional pattern more closely than the NI one. I learned the Visitor Pattern years ago in a compilers class that was taught in Java, and it was an interesting exercise to put together this example in LabVIEW. I apologize for the lack of comments and icons, I put it together rather quickly, but I hope it's helpful and I'm happy to fill in details if necessary. The example contains two class hierarchies: DataItem, and Visitor. The DataItem class has three children: IntegerDataItem, StringDataItem, and DataItemCollection (an array of DataItems). The Visitor class has two children: Generate DataItem Collection, and To Comma Separated String. The first uses the Visitor pattern to build up a DataItem Collection containing random numbers. Strings get negative numbers, Integers get positive numbers. The second visits each DataItem in the collection, and if it's a string or integer it converts to a string (if needed) and appends it to a comma-separated list. Each child of the Visitor class has a method for every child of DataItem (Visit DataItemCollection, Visit IntegerDataItem, and Visit DataItemString). To add a new action, create a new class that inherits from Visitor and implements those three methods. To get familiar with the pattern, here are some ideas for exercises: - Create a Sum class that adds all the numbers in the DataItemCollection (converting the strings to integers) - Create a TreeDisplay class that formats the DataItemCollection into a nice format for display, showing the levels of nested collections - Add a new DataItem type (for example, floating point) and add appropriate classes to each Visitor class. Note that when you want to do an action on the DataItem, you pass the Visitor (action) class to the DataItem in a call to the Do VI. This is the first level of dynamic dispatch. Then, the Do VI calls the appropriate action from the Visitor and passes the DataItem to it, adding a second level of dynamic dispatch. This is why the pattern is also known as double-dispatch. This example is in LabVIEW 2012. Visitor Pattern Example.zip
    1 point
  2. Is this a CAR for the Delete From Array? I sure wish we had visibility into the CAR database...
    1 point
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.