Mr.Zzyzzx
Mr.Zzyzzx

Reputation: 154

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)

Upvotes: 5

Views: 2883

Answers (2)

Abbas
Abbas

Reputation: 14432

I'd rather use one of the following:

GetBarsByFoo(int fooID) { }

GetBarsByMoo(int mooID) { }

GetBarsByFooId(int fooID){ }

GetBarsByMooId(int mooID){ }

Upvotes: 2

p.s.w.g
p.s.w.g

Reputation: 149050

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);

Upvotes: 5

Related Questions