Actor Framework Discussions

Showing results for 
Search instead for 
Did you mean: 

Implementing the State Pattern in Actor Framework

Thank you for your reply.

At present, I found the corresponding package in VIPM, and it works normally now😀


0 Kudos
Message 61 of 62

Hello all


Thank you for sharing this state pattern template! I hope this post is appropriate in this thread. I have recently been reading the related forums on the state pattern topic. And after some inspiration from the following videos by @justACS, I decided to check out the state pattern.


I began going through the project template and found a few things that were not quite clear.. I'd recommend checking out the project template and reading the documentation since it shows the outline for the more complex project. I decided to make a close replica to the template project. To demonstrate the simplicity of the state pattern, private data is not included in the state actors nor is there a nested ephemeral "Process Actor". This project is attached below in zip format (LV 2021 SP1). It requires the "NI State Pattern Actor" and "MGI Panel Manager" VIPM packages. Note: Go to dependencies and change the inheritance of "Panel Actor.lvclass" from "Monitored Actor" to "Actor".




The creates "UI.lvclass" root actor which launches nested actor "Process States.lvclass". I believe this is only the "Process State" object. Neither Idle or Ready objects have been created. To convince yourself, upon initialization, click on either Popup message button.. since no Popup dialog is displayed neither Idle or Ready objects have been created. More on this soon.




On the UI, there are two change state buttons: "Go to Idle" and "Go to Ready". By clicking either of these, the dynamic dispatch "" and "" shows a dialog box showing either Entry or Exit and the present state.




The two buttons below the "Go to xxxxxx" buttons are messages one can send to the nested state. Depending on which state (Idle or Ready) has been entered into (or neither upon startup explained before), the associated Popup message will only show when in that state. For example, if the current state is Ready, pressing the Idle Popup button will not do anything since it is not implemented in the Ready.lvclass. Whereas, if the Ready Popup button is pressed, you will see the Ready Popup dialog display, showing you are currently in the Ready state.




This should be rather extensible too. You can create more methods and implement private data that can be manipulated by certain states.


I hope this helps anyone new to state pattern, as it has helped me.


If it is of interest, I'll post an extended example with the "Process Actor", interfaces for messaging, and front panel logging (such as that in the project template).

0 Kudos
Message 62 of 62