Hello, I'm writing a simple multithreaded java client/server program for a college assignment. There's lots of example code online and in books which is great.
The problem I'm having is that my teacher doesn't want me to use inner classes for either the GUI event handlers or for the threads. All the example code I've seen uses inner classes for these things.
I'm trying to think of the best way to overcome this restriction. So far all I've come up with is in the server code when the server creates a new thread to service the client, to pass in as arguments to the ClientHandler thread the variables needed.
However now I'm thinking the client thread needs to broadcast a message to all connected clients this will be a method in the server class so i need to pass in a reference to the server instance into each client thread using the this keyword? Its just this doesn't seem like a very good solution.
The other idea I had was to use the Observer and Observable design pattern but this was for the client Thread to indicate to the server that it needs to be removed from the list of connected clients and if i use it to do that i don't think i can also use it to indicate that a message needs to be broadcast.
Plus if i'm passing in a reference to the server i can just have the client remove itself from the list.
The problem I'm having is that my teacher doesn't want me to use inner classes for either the GUI event handlers or for the threads. All the example code I've seen uses inner classes for these things.
I'm trying to think of the best way to overcome this restriction. So far all I've come up with is in the server code when the server creates a new thread to service the client, to pass in as arguments to the ClientHandler thread the variables needed.
However now I'm thinking the client thread needs to broadcast a message to all connected clients this will be a method in the server class so i need to pass in a reference to the server instance into each client thread using the this keyword? Its just this doesn't seem like a very good solution.
The other idea I had was to use the Observer and Observable design pattern but this was for the client Thread to indicate to the server that it needs to be removed from the list of connected clients and if i use it to do that i don't think i can also use it to indicate that a message needs to be broadcast.
Plus if i'm passing in a reference to the server i can just have the client remove itself from the list.