?
-
I have a Connection and a Client class with the former containing
"sendMessage(Message)" method. The Client contains several methods that
calls the "sendMessage(Message)" with the appropriate message, eg.
public class Client {
private Connection connection = ...
public Client() {
}
public void XXX() {
connection.sendMessage(...
}
public void YYY() {
connection.sendMessage(...
}
...
}
public class Connection {
public Connection(InetSocketAddress ..) {
...
}
...
public void sendMessage(....) {
...
}
...
}
The problem I'm having is in establishing the relationship between
Client and Connection especially on how each of them should be instantiated.
One way is to pass a Conection object to the Client class:
public Client (Connection connection) {
this.connection = connection;
}
But it looks kinda akward to have a Connection to be passed.
Another way is to pass an InetSocketAddress and then do
private Connection connection = createConnection();
....
void createConnection() {
connection = new Connection(inetSocketAddress);
}
but to me it looks akward too since there is no relationship between
Client and InetSocketAddress.
I'm sure there is a better and correct way to link them.
Thanks in advance.
"sendMessage(Message)" method. The Client contains several methods that
calls the "sendMessage(Message)" with the appropriate message, eg.
public class Client {
private Connection connection = ...
public Client() {
}
public void XXX() {
connection.sendMessage(...
}
public void YYY() {
connection.sendMessage(...
}
...
}
public class Connection {
public Connection(InetSocketAddress ..) {
...
}
...
public void sendMessage(....) {
...
}
...
}
The problem I'm having is in establishing the relationship between
Client and Connection especially on how each of them should be instantiated.
One way is to pass a Conection object to the Client class:
public Client (Connection connection) {
this.connection = connection;
}
But it looks kinda akward to have a Connection to be passed.
Another way is to pass an InetSocketAddress and then do
private Connection connection = createConnection();
....
void createConnection() {
connection = new Connection(inetSocketAddress);
}
but to me it looks akward too since there is no relationship between
Client and InetSocketAddress.
I'm sure there is a better and correct way to link them.
Thanks in advance.