上QQ阅读APP看书,第一时间看更新
Implementing the commands
Here, we have AbstractCommand, which is an abstract class with one execute method. This is the abstract command, and the execute method is implemented on the subclasses:
public abstract class AbstractCommand {
public abstract String execute();
}
In the following code snippet, we have the subclass HomeCommand, which is the implementation of AbstractCommand. The method execute() returns the path to the home page (/home.jsp):
public class HomeCommand extends AbstractCommand {
@Override
public String execute() {
return "/home.jsp";
}
}
Here, we have the LoginCommand subclass, which is the implementation of AbstractCommand. The execute() method returns the path to the login page (/login.jsp):
public class LoginCommand extends AbstractCommand {
@Override
public String execute() {
return "/login.jsp";
}
}