This is a basic naming convention question, but I didn't find anywhere that dealt with this specifically.
I have a class called Foo, and a class called Bar.
I have a method in a service to retrieve all of the Bars for a Foo. Should I name it:
GetFooBars(int fooId)
or
GetBarsForFoo(int fooId)
To expand, you could have Bars for other classes, e.g.
GetMooBars(int mooId)
or
GetBarsForMoo(int mooId)
I would suggest
GetBarsByFooId(int fooId)
GetBarsByMooId(int mooId)
Or... tweaking your API to support a call like this
[DataContract]
[KnownType(typeof(GetBarsByFooIdRequest))]
[KnownType(typeof(GetBarsByMooIdRequest))]
abstract class GetBarsRequest
{
..
}
[DataContract]
sealed class GetBarsByFooIdRequest : GetBarsRequest
{
[DataMember]
public int FooID { get; set; }
}
sealed class GetBarsByMooIdRequest : GetBarsRequest
{
[DataMember]
public int MooID { get; set; }
}
GetBarsResponse GetBars(GetBarsRequest);
I'd rather use one of the following:
GetBarsByFoo(int fooID) { }
GetBarsByMoo(int mooID) { }
GetBarsByFooId(int fooID){ }
GetBarsByMooId(int mooID){ }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With