Method Overloading. Can you overuse it?

前端 未结 16 1424
有刺的猬
有刺的猬 2020-12-02 13:38

What\'s better practice when defining several methods that return the same shape of data with different filters? Explicit method names or overloaded methods?

For exa

16条回答
  •  忘掉有多难
    2020-12-02 13:44

    I'm a total fan of the "explicit" way: giving each function a different name. I've even refactored some code which had lots of Add(...) functions in the past, to AddRecord(const Record&), AddCell(const Cell&), etc.

    I think this helps to avoid some confusions, inadvertent casts (in C++, at least) and compiler warnings, and it improves clarity.

    Maybe in some cases you need the other strategy. I haven't encountered one yet.

提交回复
热议问题