HMVC, MVC or something?
Hello,
I'm trying to solve a very common problem in the world of user interface design. How do I design for two UI's to interact with each other? I looked into the HMVC pattern, but it doesn't really make sense for this problem.
Suppose I have the following hierarchy of controllers:
A
/ \
BC
/ \
DE
I'd like "B" to post a message to "C" without them knowing anything about each other.
I could post an action to "A" which invokes all of it's children controllers "handleAction" method (just as an example). But then, controller "B" would get the action back and re-send it to controller "A" (because it cannot handle it). Controller "C" would get it eventually and consume it, but then a never ending loop could already been created between "A" and "B".
Even worse if I'd like to do something in controller "B" that should issue a invokation in controller "E". Do you get where I'm heading?
It's seems like HMVC is only from the bottom and up?
Maybe this is a very trivial problem to you GUI guru's, but I'm just a beginner in GUI design :-/
I do know I'm probably getting this with HMVC all wrong...
Please could anyone suggest a sensible design for passing messages/actions between GUI's in a large application with many frames/dialogs and not having to couple them tightly?
Kind regards, Andreas Eriksson
My personal HMVC framework has 3 features which could help.
1. Feature: The framework distinguishes between "Model Events" and "View Events".
A Model Event propagates down to inform interested controllers. e.g. the top level controller has loaded information from a database and needs to pass this information downwards.
A View Event propagates upwards. E.g. user has clicked a button to invoke a specific action.
Solution: B sends an event up. A captures it and sends a different type of event down that only C is interested in.
2. Feature: Any event can cary any arbitrary object payload.
Object payload = event.getPayload();
Solution: something in the payload makes C interested, but not B.
3. Feature: IMPORTANT!!! Every event has a source, and a CauseEvent (like chained exceptions).
Solution: if A sees itself as the source of an event, or the source of the cause ... it ignores the event.
Good luck.
-Mark
> My personal HMVC framework has 3 features which could
> help.
Are these not common in most MVC patterns implemented in Java? Don't mistake this for sarcasm, I'm no expert on patterns and am interested to know. The reason is I don't see how a complex GUI using something like Swing could function well without the things you mentioned.
To the OP. My experience has been that when creating a Java GUI using something like MVC if you run into situations where you have cyclical dependency and/or endless loops it usually means you have classes trying to do too much. In most cases taking the class and breaking it down into smaller modules that have less responsibility solved the issue.