Window Closing Technique

I have two model classes. System and Component. And two views, SystemView and ComponentView. When the SystemView is closed the ComponentView needs to be closed. However, the ComponentView does not know anything about the SystemView. The only way I have found to connect the ComponentView with the SystemView is through the models. Since Component is a subpart of System and Component knows about System, I ask Component for its System and then look for a view on that System and register a listener.

But I didnt like that way because the listener is registered rather late. Theoretically the system could have closed while the component is still registering its listener. Or while the component view was opening. So instead I have a manager class that I register all the views with. and this class tracks their relationships and when one closes it closes the others that should be closed.

This seems not very OO to me and is quite fragile. Any new views require modification of this manager class. I keep feeling like there must be a better way but am unable to put my finger on it.

[1102 byte] By [_dnoyeBa] at [2007-10-2 21:57:22]
# 1

[snip]

> ... I have a manager class

> that I register all the views with. and this class

> tracks their relationships and when one closes it

> closes the others that should be closed.

>

> This seems not very OO to me and is quite fragile.

> Any new views require modification of this manager

> class. I keep feeling like there must be a better

> way but am unable to put my finger on it.

To me this sounds like a standard implementation of the Mediator pattern. Your components register with the mediator and alert it when things change and the mediator coordinates changes to the registered components.

Lee

tsitha at 2007-7-14 1:13:28 > top of Java-index,Other Topics,Patterns & OO Design...