Method Overloading. Can you overuse it?

前端 未结 16 1406
有刺的猬
有刺的猬 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:55

    How about

    public IList GetProducts() { /* Return all. */}
    
    public IList GetProductBy(int productId) {...}
    public IList GetProductBy(Category category) {...}
    public IList GetProductBy(string Name ) {...}
    

    And so on?

提交回复
热议问题