[英]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. 我有一个名为Foo的类,还有一个名为Bar的类。
I have a method in a service to retrieve all of the Bars for a Foo. 我在服务中有一个方法来检索Foo的所有Bars。 Should I name it:
我应该说出来吗:
GetFooBars(int fooId)
or 要么
GetBarsForFoo(int fooId)
To expand, you could have Bars for other classes, eg 要扩展,你可以为其他类提供Bars,例如
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 或者 ......调整您的API以支持这样的调用
[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){ }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.