Giter Site home page Giter Site logo

tdd_hw01's Issues

review completed

API 的設計很不錯,用 generic lambda 是一個很有彈性,讓使用端很好用的方式。幾個建議:

  • 如果設計成針對 IEnumerable<T> 的 extension method, 在測試案例的描述上,API的使用上,會比現在再方便一些。

  • DoAggregate() 如果是回傳 IEnumerable<T> 而不是放到 property 上,就可以用 yield return 來處理回傳結果,寫起來會比目前的 production code 更簡潔。

結論

設計

可以參考一下我的 sample code: https://gist.github.com/hatelove/f5a4c2591293828b637f#file-getsumbypagesize_v2-cs

重點 focus 在下列幾點:

  1. 呼叫端怎麼呼叫最好用, 語意清楚, 參數夠少, intellisense輔助。
  2. API 在需求異動時,能越穩定越好,代表支援有足夠的彈性。在面對重構時,也不會影響到呼叫端的使用,例如 property rename。
  3. 測試案例要怎麼呈現,最像口語化的描述著呼叫端使用情境。包含怎麼寫語意最清楚,寫起來最快。

這個 homework 基本上有四種方式來實作,也考驗著對 C# 的熟悉程度。

  1. 使用 enum, production code 以 if/else 來分辨
  2. 使用 string + reflection 來動態決定使用哪一個 property 加總
  3. 使用 delegate/lambda 針對 Product 型別來處理
  4. 使用 generic 支援泛型,使用 extension method 針對所有集合都提供這樣的功能

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.