LabVIEW Development Best Practices Documents

Showing results for 
Search instead for 
Did you mean: 

Command Pattern for LabVIEW OOP


Encapsulate commands or actions and information to perform them ithin an object.  This implementation places commands into a queue.  You can set up historical data on commands sent for purposes of undo/redo operations or logging.


You want to process a number of different commands with the same object.  They may have different data and have distinct action implementations by the receiver that performs the actions.  You may want to place them into a queue or other ordering hierarchy for execution.   The reciever may have resources that different commands share.


This implementation represents a stock trading system. 

The main launcher allows the user to invoke trades through an agent and see that the stock trader object executed them via Display String on the front panel.  The stock trader receives and implements all the orders the agent sends it.  The stock trader updates the main launcher's front panel using a Display string user event created before the main loop starts..

The orders are sent through a queue stored in the stock trader object.  Place order is used to place an order into the stock trader's queue.  The stock trader pulls the order that is next in line for execution from the queue when execute order is called.  You could add a command to check the queue between command on timeout/idle state and execute anything waiting.

Each order type (Buy and Sell) are children of the main order class and their execute functions behave differently.


For your Command class, order.lvclass, you will want to set the execute to require override.


I made an effort to reference the generic naming convention for all my classes in comments as they were used (ie, the Agent is invoker, the Stock Trader is the receiver).

Editorial Comments

References used:

Here is the best short/clear description I found of this pattern:

I used a number of  examples of the same pattern, mostly in C# to implement this. 

Here is the same idea implemented in Java:

And here in C#:

Here is a generic and Calculator implementation in C#: