Inter-class comunications


#1

Hello,

What is the right way to intercommunicate two or more independent classes in Juce?

If my classes knows other classes pointers and types, then I am using Component::postCommandMessage() and 
Component::handleCommandMessage(), and it works.
 

If not, I see that there are Message and MessageListener classes, but I don't know how to use them to exchange messages from one class to other.

Should I use ActionBroadcaster and ActionListener instead? How?

Thanks

 


#2

What type of communication do you want to do? Is it across threads? Is it important to keep coupling to a minimum? The reason I ask, is that commuicating between 'classes' in code is a simple process of the class having knowledge of the class (compile time) it wants to call, and a pointer to the actual instantiation (runtime).


#3

I would like to send a message/event from a ToolbarButton to the MainComponent where the toolbar that contains that button is instanced.

From the button I can get the MainComponent pointer with findChildWithID method, but I think it is not a nice way because it forces me to make an include of MainComponent from my ToolbarItemFactory and make its methods public.

So I am looking for a beeter way.

 

MainComponent ---> Toolbar ---> ToolbarItemFactory ---> ToolbarButton -->event                       

In MainComponent I would have an event handler to receive the ToolbarButton's event.

 

may be an ActionBroadcaster?