設計理念
- 顯示/新增/刪除 TodoList
- TodoList 會是一堆 todoItem 的集合,所以要定義 todoItem 的形別
- Content : todoItem 的內容
- Status : todoItem 的狀態,完成(done)、未完成(undo) ,設計成列舉
- 主要的功能
- 建立 todoItem
- 完成 todoItem
- 繪製 todoList 到前端的畫面上
自我分析
跟 UI 耦合太高,Render 應該與 TodoService 分離 ,
DOM 註冊事件相依在 Service 裡面要抽離也不好抽 。
沒有先寫測試 , 要想一想怎麼與 UI 層作隔離。
程式碼
建立 BaseService
1 | class BaseService<T> { |
建立 todoItem interface
1 | interface todoItem { |
建立 todoItem Status 列舉
1 | enum todoStatus { |
建立 TodoService
1 | class TodoService extends BaseService<todoItem> { |
使用建立好的 TodoService
1 | var todoService = new TodoService(); |
(fin)