Im trying to apply the state pattern on a multi threaded application.The problem is that the compiler doesnt like the fact that my class extends Thread. Here is the code :
public class ConnectionHandler extends Thread
private State lockedState;
public ConnectionHandler(Socket socket){
...
lockedState = new LockedState(this);
}
public State getState(){}
public void setState(State state){}
{
public interface State {
public void PASSWD(String pass);
public void ACCESS(String file);
public void getDIR();
public void QUIT();
}
public class LockedState implements State {
ConnectionHandler connectionHandler;
public LockedState(ConnectionHandler handler){
connectionHandler=handler;
}
public void PASSWD(String pass){
public void ACCESS(String file){}
public void getDIR(){}
public void QUIT(){}
}
The error i get is on constructor of ConnectionHandler : incompatible types required java.lang.Thread.State found : Networks2.LockedState. When i remove the extends Thread from Connectionhandler it doesnt give any errors but thats not an option. So the question : What should i do so that the compiler doesnt complain ? Thanks