Singular method name for single object argument, plural for list?

I am having a problem with the method name for a database application.

In my instance Database

, I have a method that can remove an object Agreement

from the database. However, I want to be able to delete multiple at once Agreement

in order to be able to use transactions. The problem is that I also have an overload for deleting one object Agreement

.

Essentially my structure looks like this:

public class Database
{
    // ...

    public void RemoveAgreement(Agreement a)
    {
        // ...
    }

    public void RemoveAgreement(IEnumerable<Agreement> agreements)
    {
        // ...
    }
}

      

But this can be confusing, since the combo overload Agreement

has a singular name, even though it is inherently plural.

My question is, how should I structure it? Should I have two named overloads RemoveAgreement()

or RemoveAgreements()

? Or should I use two separate methods instead of overloads?

Thanks.

+2


a source to share


3 answers


I would say that for a method that receives a list as a parameter, the name RemoveAgreement

is incorrect for the reason you describe.

I would call it RemoveAgreements

For the name of your class (database), I would say that you use it as DAO for ALL of your entities.

If you used this class ONLY for convention objects, I would have these 2 methods



public void Remove(Agreement agreement)

and

public void Remove(IEnumerable<Agreement> agreements)

+6


a source


I recommend using separate names and overloading the multiple version that accepts params Agreement[]

.



0


a source


Here's what I would do in this situation:

public void RemoveAgreement (Agreement agreement)
{
    // Do Stuff
}

public void RemoveAgreements (IEnumerable<Agreement> agreements)
{
    foreach (Agreement a in agreements)
    {
        RemoveAgreement(a);
    }
}

      

0


a source







All Articles