Question

Maybe it's not worth worrying about in this scenario, but lets say you have two classes, a JFrame with all its components, and a server-like class that handles requests from remote clients. The user is able to start and stop server objects through the GUI, and is shown various events that happen to each server object. Whether or not I use an explicit pattern (like MVC), it seems like the JFrame needs a reference to the server class (to call start and stop) and the server needs a reference to the JFrame (to notify of it of certain events).

Is this a problem, or am I looking at this situation in the wrong way?

Was it helpful?

Solution

This sounds like a place to apply the Listener pattern. Your server could have a method called addSomethingListener(SomethingListener listener), which the JFrame calls with an implementation of SomethingListener. Your server then would call the listener's methods whenever appropriate events happen.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top