- Java EE 8 Design Patterns and Best Practices
- Rhuan Rocha Jo?o Purifica??o
- 128字
- 2021-07-23 16:54:53
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";
}
}
推薦閱讀
- 嵌入式Linux開發技術
- Cybersecurity:Attack and Defense Strategies
- 大學計算機應用基礎實踐教程(Windows 7+Office 2013)
- 嵌入式Linux系統開發:基于Yocto Project
- 精解Windows8
- Implementing Azure DevOps Solutions
- Windows 7中文版從入門到精通(修訂版)
- ElasticSearch Cookbook
- 寫給架構師的Linux實踐:設計并實現基于Linux的IT解決方案
- 從零開始學安裝與重裝系統
- OpenVZ Essentials
- 完美應用Ubuntu(第2版)
- 辦公自動化教程(Windows7+Office2010)
- 程序員必讀經典(算法基礎+計算機系統)
- SQL Server on Azure Virtual Machines