I am having a reference to a viewComponent class ( say A_View ) inside a mediator ( SystemMediator )
Why is the mediator not called A_ViewMediator instead of SystemMediator? Generally the mediator is named according to the component it tends.
So naturally SystemMediator can use the reference of this viewcomponent to access all the member functions of A_View. So, is this ok ? I am doubtful ?
If SystemMediator's reference to A_View is by having a reference to A_View's parent in the display list, then no, you should not manipulate A_View from SystemMediator, but should instead, either:
A) Have A_View's parent in the display list encapsulate interaction with A_View (i.e. expose a method that SystemMediator can call and have that method do the interaction with A_View)
B) Mediate A_View and then A_View's mediator can make calls to A_View's methods and set its properties.
Should i use sendNotification to access the A_Mediator and then access the member function of A_View.
I assume you mean should another actor, such as a command, send a notification to SystemMediator who'll respond by interacting with A_View. Yes, this is the appropriate way of interacting with A_View from elsewhere in the app.
But why should i adopt this roundabout way when reference is present in SystemMediator./quote]
Because it isolates the knowledge of A_View to a single actor - its mediator. This is an example of the loose-coupling we desire in OOP. If you spread knowledge of a component around the system, it makes it difficult to replace that component or change its API without having to refactor all the classes that know it.