I have a RequestHandler class and a RequestListener class. A RequestHandler creates a RequestListener and passes it a reference to itself. The RequestListener in turn calls methods on the RequestHandler to handle requests of different types when they are processed (eg handleTypeARequest(), handleTypeBRequest() and so on). Unfortunately, the RequestHandler also calls methods on the RequestListener (eg processNextRequest()), so I have a circular dependency:
class RequestHandler {
RequestListener requestListener;
...
}
class RequestListener {
RequestHandler requestHandler;
...
}
This means tighter coupling between the two and is generally considered to be a code smell.
One solution would be to use different objects to encapsulate each request instead of different methods. A RequestListener could, when prompted, process a request and return some type of Request object for it. Unfortunately, I don't really like this approach, in part because of the added complexity of more objects and classes and in part because of the performance issues (which matter here); calling handleXXXRequest() methods on the RequestHandler directly is much faster than creating a bunch of objects and probably also maintaining a stack to buffer them until needed.
Are there any other solutions to this problem, and also, is it really a problem?