Actor Framework Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Abstract messages and Inheritance

Hi,

 

I am quiet new in actor framework but I spend quiet long time in forums in order to understand how it worked. Now I am struggling to use Abstract messages to obtain low coupled and reusable actors when coupled with Actor Inheritance. I look for information in the forum (like this one https://forums.ni.com/t5/Actor-Framework-Documents/Beginner-Tutorial-Zero-Coupled-Actor-Project/ta-p...) but I am not sure to do everything right since it is not really straight forward. I created two small examples to show what I do not fully understand.

 

The purpose of this example is very simple, an actor (sender) have a text field and as soon as it is modified, It should send this information to another actor (receiver). A main actor, that launch the 2 sub actors, is used to control the entire system. So the "Sender" send the message the the "Main", and the "Main" send the message to the "Receiver". 

 

I first tried with concrete message( Test Actor Coupled). It worked well, but I then realized that without using abstract message, the sender would use the send Msg function of the Main actor. Therefore they will be strongly coupled.

 

So I modified the project to have decoupled actors (Test Actor Decoupled.zip) . Therefore I created an abstract message own by the Sender. I had to modify 5 part of the code:

- I created an abstract message own by the sender

- I created a concrete implementation of this message own by the main actor

- Modify Main Actor core to "notify" the sender actor that it should implement this version of this data

- create an accessor for the Sender-> Send String Msg class parameters

- modify the part of the Sender.Actor core.Vi to send an abstract message from the caller and connect the accessor to the Send String Msg.

 

Is it the proper way to do this ? I thought that somehow the caller reference would be enough to detect which implementation of the function should be used. And I also realized that the Sender is not anymore coupled with the main, bu the main depends (inherits) on the Update String Msg class. So this won't be easy to replace my sender class with another on. Is it also unavoidable behavior?

 

Then I wanted to test the inheritance with actor, so I created two receiver classes (one parent and one child). The main actor would launch either the parent or the child class. 

 

In order to enable the communication between the "Main" and the "Receiver", I created an abstract class (Update String AMsg -- A for Abstract) and two instance of this abstract message : one owned by the Receiver Parent class and one by the Receiver Child class.

 

To send the message from the main to the receiver, I had to do quiet many modifications in the Main class:

I had to notify the receiver class which message to used depending on which class was selected (as shown in the Modif Abstract message Receiver). Then I had to create a structure in the main message to store the message (Message Class). Then I had to modify the part of the code that send message as shown in Modif Abstract message Receiver Msg.jpg

 

This is doable with a single message but it will certainly become quiet complicated with real world project with many messages

 

I place in copy two example projects: the one with coupled actor and the one with decoupled actor.

 

I would be really pleased if anyone can help me to have a better overview of the Implementation of inheritance with this actors

 

BTW I also tried to use an array of messages in the main Actor -  but the Actor Core.vi does not compiled anymore in that case.

PS : Sorry for the long message and thank you for reading it until the end

Message 1 of 1
(2,712 Views)