tdd91_hw2_shoppingcart's People
tdd91_hw2_shoppingcart's Issues
review completed
大部分 comment 都在各 commit 裡,幾點建議:
- API 在一開始就得依據已知的所有需求進行設計,所以在寫第一個紅燈時,API就不會隨便開。
- 最後的 PotterBook 那一堆 class 跟 interface 都是 over design,因為沒有意義,它就是 Book, 只是名字不一樣。
- 最終的 production code 命名看得出來試圖讓程式碼可讀性提昇,但對理解算法上幫助不大。
- 最大的問題在於,紅燈、綠燈的過程,綠燈都是一路硬幹,到最後再一次針對完整需求進行重寫。這樣是白費力氣。可以參考下面的 sample solution 歷程。
Sample Solution
2016 舊版
https://github.com/hatelove/PotterShoppingCart/commits/anotherRefactor
我的演算法也寫得不夠好, 但對外的 function 主流程很清楚:
- 防呆
- 整理出有幾套書
- 加總每一套折扣完的總價
2017 版本
2017 新版 production code 作法 (中間過程因為一些緣故有漏 commit 檔案)
- 取得總共幾套
- 每一套依據折扣計算出該套金額
- 加總每一套的金額
TDD 演進過程主要步驟
- 產生 production code API
- 計算總價 = 單價 * 數量
- 計算一套的金額 = 總價 * 折扣
- 將所有書分成 N 套
- 對每一套計算折扣金額後加總
API設計要點
你在動手寫任何 code 之前,應該有眼前已知完整的需求,以這為前提,在第一個紅燈時把 API 設計好。既要考慮到眼前已知的所有需求,又不能腦補可能發生也可能不會發生的需求,並以需求的 domain 為主軸,命好名字,考量該怎麼用,API 才具備易用性,呼叫端才是最方便使用的。
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.