I am currently working on a semi-large project that has several packages. There are 3 main packages, a “client” package, a “server” package and a “common” package. There are two jars, one for the client and one for the server each containing their own package and the common package. As is implied by the package names, there is a server and a client. The clients connect to the server and exchange messages. These messages take the form of a serilized subclass of Message. All subclasses of Message are in the common package. When a message is recieved, a method is called on the message class to handle the message. There is one subclass of Message that is responsible for sending the name of the clients to the servers. In the method that is called when the server recieves it, it then calls a setName() method on the object representing the connection between the server and client.
For obvious reasons, I don’t want external programmers calling the setName() method however it has to be public because the message and the class to represent a connection are in different packages. I would like to know if it is good form to deprecate the method with a reason along the lines of “for internal use only”, and if not, what is a better option?
7
You may need to consider some re-structuring.
So it looks like we have [Client] -message-> [Server] and Message (and all derivatives of) are stored in the [Common] package. In your comment you explain that the Message contains a function which gets called by either the Server or the Client depending on which received the message, which in turn calls a method on either the client or the server.
In my eyes, and just from what I can gather from your explanations, is that you should consider writing the message handling mechanisms right into either the client and server portions instead of having the message handling included as part of the message class.
1