Actor Framework Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

How to override a parent Actor

Solved!
Go to solution

Time for another simple question: How can we make a child actor override a parents method?

I am working off the assumption that I only override the actor class, not the message class as well. The child class implements method.vi with dynamic dispatch terminals, and when this is called by the parent's Method Msg Class Do.vi the actor that is passed into it is of child, and so the child method is called. Am I missing something here - I wonder if there is a "Call Child method" vi needed to be used or something like that?

Thanks,

Rik

0 Kudos
Message 1 of 4
(4,185 Views)
Solution
Accepted by topic author rik_aspinall

Actually I think this is correct... a simple message box saying "Parent method" and "Child method" showed that this was the case! I'll leave this up in case it helps anyone as I didn't see many search hits.

0 Kudos
Message 2 of 4
(3,529 Views)

If I understand you correctly, I think you have it right. The parent actor has a dynamic dispatch method which a message class was created to call (using the Actor Framework Message Maker tool usually). A child class is then created (create a new class and set its inheritance to the parent actor) and the parent's method is overriden. This is done by right clicking the child class, selecting New->VI for Override..., and choosing the desired parent method.

Now if you launch the child actor and send it the message created for the parent actor, the child's implementation is called instead. You can also choose to call the parent's implementation in addition to whatever the child's method does.

The above can be useful when designing a stand alone actor that you don't want to modify for each program you use it in. The stand alone actor sends messages to itself with new data or notifications. You can then create a child class of that actor, override the methods called by the messages, and then send the data to your root actor (using a message) or wherever you want. Now all you have to do is launch the child actor in place of the original, and you get access to the data and notifications it generates. This is one way of loosly de-coupling actors; the stand alone actor is unaware of anyone else, but your child actor is tightly coupled to whatever actor it sends data to.

0 Kudos
Message 3 of 4
(3,529 Views)

rik: You got it right. Actors ARE classes. Anything that is true of the classes is true of actors. So if the parent has a method and the child needs to override it, it can. The message invokes the dynamic dispatch method and it calls the right one for the running actor.

0 Kudos
Message 4 of 4
(3,529 Views)