views:

701

answers:

3

What is difference to the controller that gets the return with repect to rendering the List?

In 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();
    }
+8  A: 

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.

Andrew Kennan
what he said -> always try and return Interfaces instead of the concrete type. Why? If you decide to change the concrete type (which impliments that interface) you shouldn't have to change the code that depends on that method (unless u need the new functionality of the new concrete class).
Pure.Krome
+1  A: 

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.

tvanfosson
A: 

Consider returning an array, consider accepting IEnumerable as a parameter.

Matt Hinze