- Intent
To define the skeleton of a function in an operation, deferring(推遲) some steps to its subclasses. The Template Method lets subclasses redefine certain steps of a function without changing the structure of the function. The HttpServlet does this in the servlet API.
- Benefits
拿來做程式碼重用的最佳選擇
- 適用情境
- 有一部分的邏輯運算可先行被定義,而將其他可供動態重新定義的method留給子類別override的。
- 具有一些通用性的功能的,可以抽放到這個範本類別
- Class Diagram
[caption id="attachment_278" align="alignnone" width="177" caption="Template Method"][/caption]
沒有留言:
張貼留言