Message Transfer b/w Objects

  • Thread starter Shravan Kumar Durvasula
  • Start date
S

Shravan Kumar Durvasula

Hi all:

Here (http://www.erc.msstate.edu/~shravan/Hierarchy_files/slide0001.htm)
is the hierarchy of the Java Swing application i want to develop. I
have a "MainFrame" which has three panels (A, B and C). Those panels
have sub panels ((A1, A2) (B1, B2) (C1, C2)). I have objects (which i
am actually planning to implement as independent pluggable components
using the "Observer" pattern) on these sub panels.

Now let us say an event happens on "Obj O1" (changes state) and this
should trigger a change on "Obj O10" and "Obj O12". What is the best
way to implement this? I mean .. how can we transfer a message from an
object somewhere in the tree to another object somewhere else in the
tree? Because i am implementing object O1 as pluggable component
(using Observer pattern), i can add O10 and O12 as listeners
(Observers) to it. But, how can i get the reference of O10 and O12 in
the panel A1?

Could anyone please advice?

Thanks a lot in advance,
Shravan
 
D

David Hilsee

Shravan Kumar Durvasula said:
Hi all:

Here (http://www.erc.msstate.edu/~shravan/Hierarchy_files/slide0001.htm)
is the hierarchy of the Java Swing application i want to develop. I
have a "MainFrame" which has three panels (A, B and C). Those panels
have sub panels ((A1, A2) (B1, B2) (C1, C2)). I have objects (which i
am actually planning to implement as independent pluggable components
using the "Observer" pattern) on these sub panels.

Now let us say an event happens on "Obj O1" (changes state) and this
should trigger a change on "Obj O10" and "Obj O12". What is the best
way to implement this? I mean .. how can we transfer a message from an
object somewhere in the tree to another object somewhere else in the
tree? Because i am implementing object O1 as pluggable component
(using Observer pattern), i can add O10 and O12 as listeners
(Observers) to it. But, how can i get the reference of O10 and O12 in
the panel A1?

Could anyone please advice?


Have you considered making the Main frame a mediator, or creating a mediator
at the main frame level? You could just have it listen for changes in the
O1's state and have it modify O10 and O12. This seems to be the common
approach for GUIs.
 
S

Shravan Kumar Durvasula

Well David .. i was actually thinking about putting a Mediator that
could possibly communicate to all of the objects. On the otherhand ..
i was not sure if it could be called a MVC design?

Is there any tutorial where we can know how to develop MVC based
front-ends.

Thanks a lot in advance,
Shravan
 
D

David Hilsee

Shravan Kumar Durvasula said:
Well David .. i was actually thinking about putting a Mediator that
could possibly communicate to all of the objects. On the otherhand ..
i was not sure if it could be called a MVC design?

Is there any tutorial where we can know how to develop MVC based
front-ends.

I don't know of any good tutorial that shows you how to develop front ends
using MVC. Google might help you there.

I don't see how a Mediator would violate MVC. Multiple design patterns may
be used inside an application. In your application, the Mediator is a part
of the model that manages the interactions between the other model objects
(O1, O2, etc). The O1, etc objects are not the model; they are a part of
the model. Some may argue that the Mediator and all of the O1, O2, etc
objects should be contained inside a well-defined Model object, and I could
see how that might be cleaner and more in line with MVC.

Of course, this is all my opinion and an OO enthusiast could jump in and say
I'm crazy. Personally, I don't worry about whether or not I'm staying true
to a design pattern. Most of the Java swing applications I've seen are not
MVC and instead opt for a Model with a View+Controller in the same class (if
that).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top