Interobject Communication

I have a custom control (note : Swift) and I need to have various properties and events commuicate both directions between various embedded controls

Class A - is the “container” that is the only PUBLIC object, so any properties (colors, fonts etc) are exposed here… and setting appropriate properites on the internal items is fine
Class B and C are both “canvas” type views, click events etc are sent to Class A via protocol delegates
Class D is a ScrollView
Class E is a TextView

Swift Menu events (ie. EnableMenuItems) are required to be at the level where the actions (cut,paste etc) would happen, this would be Class D

The problem I am facing is the best way for Class E to “know” about various properites of Class B and C (are they visibile, amongst other things). Espeically since Class A is the parent of all the instances.

The only way so far, is to create variables OUTSIDE class A that are public, and that is not a good practice, nor is having a given class hold a reference to an instance of antoher class

in Xojo you might use an Event in B C D and E that could be implemented in A for those to get / send information to / though A to other views

Dunno if you have that kind of facility

The other possibility is to use messages or notifications within the app to say “hey something changed” and then have one of the views respond to that notification (it might still have to call an exposed method on the other object to do this though)

Events I can do using delegates… a bit of a pain… the problem is when “E” needs to know an attribute of “B”

Since “E” controls the menu… it needs to know what to enable, add checkmarks etc.

Hmmmm… how about if I added an attribute to B, C, D and E that was a weak reference to “A”… and then use that to query everything? Technically each class would refernce to another class, but only indirectly…

In Xojo since A could roughly be “the controller” it would mediate E’s request to B
Swift might configure that differently but …

The controller is a parent
The children have a reference to the parent?
Public properties of the parent could be set by the children, and read by other children.

Akin to properties of ‘app’ object in a Xojo app…?

Look into the Notification Center. I modeled the OWNotificationCenter on the Cocoa one. Allows you to broadcast messages to registered objects.

That is fine for events (which I handled using delegates)… it is when it need to reach into another class instance and get a property value.

I just added a property to each of the classes called “parent” which is the class that it would need to query later on… so far this is working perfectly. Probably would not be a great solution if these were all generic reusable classes, but they are very specific and of no use outside the bounds of “Class A”

Thanks