Actor Framework Discussions

cancel
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
(902 Views)

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.

 

https://www.youtube.com/watch?v=GRDoyn1mNAI

https://www.youtube.com/watch?v=yVzT5ZqUuVU

https://www.youtube.com/watch?v=gz_6FTE1__8

 

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".

 

NathanDavis_0-1720846462760.png

 

The Launcher.vi 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.

 

NathanDavis_2-1720847302076.png

 

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

 

NathanDavis_4-1720849310618.png

 

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.

 

NathanDavis_5-1720849350749.png

 

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
(501 Views)