Overview
The example builds showing how MVC can be as simple as an Event Based Queued State Machine through to using the Command Pattern to allow for extensibility and then on to using the Factory Pattern to use plug ins to extend it even further.
Description
The example builds showing how MVC can be as simple as an Event Based Queued State Machine through to using the Command Pattern to allow for extensibility and then on to using the Factory Pattern to use plug ins to extend it even further. The first VI to run and examine is the MVC Starter. This breaks the code into two. The top loop is the View and the bottom one the Controller. The Model is the data in the two shift registers on the bottom loop containing the frequency and waveform data. One point to note is the user event to put data into the View and then onto the Waveform Display where this would normally go in the controller. This split is important in making this MVC. The next VI, MVC OOP, does exactly the same job but now encapsulates the frequency and waveform data into a class, with read and write methods to get data out of and put data into the class. The next VI, MVC OOP Advanced, extends the functionality of this by adding the option to change the type of waveform used. Whilst normally this would change the original class it does not in this project so that both may exist in parallel in the project. All of the examples to this point are using the cluster of enum and variant to pass command and data from the View to the Controller. The next example, MVC OOP Advanced with Commands, changes this to use classes to send the message between the loops. There is a parent class ‘Message.lvclass’ which is used to create the queue and has an execute method that can be overridden to provide functionality. This is uses dynamic dispatch to carry out the actions previously done in the state machine. Each previous action now a method of a class, which is a child of ‘Message.lvclass’, and carries out it's Execute method to run the action.
The final part of the example is MVC OOP Advanced with Commands and Factory which extends the previous example to use the Factory Pattern to allow the user to create plug ins to create their own waveforms, load them in from disk etc. On initialization it scans a directory for .lvclass files in a directory and then loads the class in from disk to carry out the generation task. The Dynamic Dispatch VI shows the concept by pouring beer. Dependent on the type of beer that is requested, the pour method is altered to suit the type of beer.
Requirements
- LabVIEW 2012 (or compatible)
Steps to Implement or Execute Code
- Unzip the attached folder to your computer
- Open the project "MVC Example.lvproj"
- Open and Run the different VI as you wish
Additional Information or References
VI Block Diagram of "MVC Starter.vi" (Check other VIs in project)
**This document has been updated to meet the current required format for the NI Code Exchange.**