What is difference to the controller that gets the return with repect to rendering the List?
获得返回的控制器与渲染List有什么区别?
In Linq dataContext:
在Linq dataContext中:
public IList<Response> GetResponses(int ID)
{
var responses = from r in this.Responses where r.ID == ID orderby r.Date select r;
return responses.ToList();
}
OR
public List<Response> GetResponses(int ID)
{
var responses = from r in this.Responses where r.ID == ID orderby r.Date select r;
return responses.ToList();
}
3 个解决方案
#1
I doubt there's much difference to the controller but you should probably try to reveal as little information as possible about the private data of your classes. This means exposing interfaces rather than concrete types and using the interface that exposes the minimum amount of information the client will need to operate on the data.
我怀疑控制器有很大的不同,但您应该尝试尽可能少地了解您的类的私有数据。这意味着暴露接口而不是具体类型,并使用暴露客户端将需要对数据进行操作所需的最少量信息的接口。
If the controller only needs an IEnumerable<Response>
then you should consider making that the return type of GetResponses
.
如果控制器只需要一个IEnumerable
#2
The difference is that the controller won't need to be updated if you change your List implementation if you use the IList interface. It's probably not that big of a deal unless you are planning to make your library available to others. In that case the abstraction is probably justified as you won't be the only one having to update your code if you make the change.
不同之处在于,如果使用IList接口更改List实现,则无需更新控制器。除非您计划将图书馆提供给其他人,否则这可能不是什么大不了的事。在这种情况下,抽象可能是合理的,因为如果进行更改,您将不是唯一必须更新代码的人。
#3
Consider returning an array, consider accepting IEnumerable as a parameter.
考虑返回一个数组,考虑接受IEnumerable作为参数。
#1
I doubt there's much difference to the controller but you should probably try to reveal as little information as possible about the private data of your classes. This means exposing interfaces rather than concrete types and using the interface that exposes the minimum amount of information the client will need to operate on the data.
我怀疑控制器有很大的不同,但您应该尝试尽可能少地了解您的类的私有数据。这意味着暴露接口而不是具体类型,并使用暴露客户端将需要对数据进行操作所需的最少量信息的接口。
If the controller only needs an IEnumerable<Response>
then you should consider making that the return type of GetResponses
.
如果控制器只需要一个IEnumerable
#2
The difference is that the controller won't need to be updated if you change your List implementation if you use the IList interface. It's probably not that big of a deal unless you are planning to make your library available to others. In that case the abstraction is probably justified as you won't be the only one having to update your code if you make the change.
不同之处在于,如果使用IList接口更改List实现,则无需更新控制器。除非您计划将图书馆提供给其他人,否则这可能不是什么大不了的事。在这种情况下,抽象可能是合理的,因为如果进行更改,您将不是唯一必须更新代码的人。
#3
Consider returning an array, consider accepting IEnumerable as a parameter.
考虑返回一个数组,考虑接受IEnumerable作为参数。