Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 68659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:27:04+00:00 2026-05-10T19:27:04+00:00

What’s better practice when defining several methods that return the same shape of data

  • 0

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 example. If I have some Products and I’m pulling from a database

explicit way:

public List<Product> GetProduct(int productId) {    // return a List    } public List<Product> GetProductByCategory(Category category) {    // return a List    } public List<Product> GetProductByName(string Name ) {    // return a List    } 

overloaded way:

public List<Product> GetProducts() {    // return a List of all products    } public List<Product> GetProducts(Category category) { // return a List by Category } public List<Product> GetProducts(string searchString ) { // return a List by search string } 

I realize you may get into a problem with similar signatures, but if you’re passing objects instead of base types (string, int, char, DateTime, etc) this will be less of an issue. So… is it a good idea to overload a method to reduce the number of methods you have and for clarity, or should each method that filters the data a different way have a different method name?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T19:27:05+00:00Added an answer on May 10, 2026 at 7:27 pm

    Yes, overloading can easily be overused.

    I’ve found that the key to working out whether an overload is warranted or not is to consider the audience – not the compiler, but the maintenance programmer who will be coming along in weeks/months/years and has to understand what the code is trying to achieve.

    A simple method name like GetProducts() is clear and understandable, but it does leave a lot unsaid.

    In many cases, if the parameter passed to GetProducts() are well named, the maintenance guy will be able to work out what the overload does – but that’s relying on good naming discipline at the point of use, which you can’t enforce. What you can enforce is the name of the method they’re calling.

    The guideline that I follow is to only overload methods if they are interchangable – if they do the same thing. That way, I don’t mind which version the consumer of my class invokes, as they’re equivalent.

    To illustrate, I’d happily use overloads for a DeleteFile() method:

    void DeleteFile(string filePath); void DeleteFile(FileInfo file); void DeleteFile(DirectoryInfo directory, string fileName); 

    However, for your examples, I’d use separate names:

    public IList<Product> GetProductById(int productId) {...} public IList<Product> GetProductByCategory(Category category) {...} public IList<Product> GetProductByName(string Name ) {...} 

    Having the full names makes the code more explicit for the maintenance guy (who might well be me). It avoids issues with having signature collisions:

    // No collisions, even though both methods take int parameters public IList<Employee> GetEmployeesBySupervisor(int supervisorId); public IList<Employee> GetEmployeesByDepartment(int departmentId); 

    There is also the opportunity to introduce overloading for each purpose:

    // Examples for GetEmployees  public IList<Employee> GetEmployeesBySupervisor(int supervisorId); public IList<Employee> GetEmployeesBySupervisor(Supervisor supervisor); public IList<Employee> GetEmployeesBySupervisor(Person supervisor);  public IList<Employee> GetEmployeesByDepartment(int departmentId); public IList<Employee> GetEmployeesByDepartment(Department department);  // Examples for GetProduct  public IList<Product> GetProductById(int productId) {...} public IList<Product> GetProductById(params int[] productId) {...}  public IList<Product> GetProductByCategory(Category category) {...} public IList<Product> GetProductByCategory(IEnumerable<Category> category) {...} public IList<Product> GetProductByCategory(params Category[] category) {...} 

    Code is read a lot more than it is written – even if you never come back to the code after the initial check in to source control, you’re still going to be reading that line of code a couple of dozen times while you write the code that follows.

    Lastly, unless you’re writing throwaway code, you need to allow for other people calling your code from other languages. It seems that most business systems end up staying in production well past their use by date. It may be that the code that consumes your class in 2016 ends up being written in VB.NET, C# 6.0, F# or something completely new that’s not been invented yet. It may be that the language doesn’t support overloads.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 93k
  • Answers 93k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In general this is safe from the perspective of not… May 11, 2026 at 6:39 pm
  • Editorial Team
    Editorial Team added an answer but the responseSource that gets dumped is, as far as… May 11, 2026 at 6:39 pm
  • Editorial Team
    Editorial Team added an answer Calling GetType() on a value type boxes that value type.… May 11, 2026 at 6:38 pm

Related Questions

Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Seemingly simple, but I cannot find anything relevant on the web. What is the
What is a programmer’s life like?

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.