Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming convention for service method

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)
like image 253
Mr.Zzyzzx Avatar asked Mar 19 '13 15:03

Mr.Zzyzzx


2 Answers

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);
like image 69
p.s.w.g Avatar answered Sep 20 '22 22:09

p.s.w.g


I'd rather use one of the following:

GetBarsByFoo(int fooID) { }

GetBarsByMoo(int mooID) { }

GetBarsByFooId(int fooID){ }

GetBarsByMooId(int mooID){ }
like image 35
Abbas Avatar answered Sep 22 '22 22:09

Abbas