using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Wrox.ProCSharp.LINQ
{
public class Formula1
{
public static IList<Racer> GetChampions()
{
List<Racer> racers = new List<Racer>(40);
racers.Add(new Racer("Nino", "Farina", "Italy", 33, 5));
racers.Add(new Racer("Alberto", "Ascari", "Italy", 32, 10));
racers.Add(new Racer("Juan Manuel", "Fangio", "Argentina", 51, 24));
racers.Add(new Racer("Mike", "Hawthorn", "UK", 45, 3));
racers.Add(new Racer("Phil", "Hill", "USA", 48, 3));
racers.Add(new Racer("John", "Surtees", "UK", 111, 6));
racers.Add(new Racer("Jim", "Clark", "UK", 72, 25));
racers.Add(new Racer("Jack", "Brabham", "Australia", 125, 14));
racers.Add(new Racer("Denny", "Hulme", "New Zealand", 112, 8));
racers.Add(new Racer("Graham", "Hill", "UK", 176, 14));
racers.Add(new Racer("Jochen", "Rindt", "Austria", 60, 6));
racers.Add(new Racer("Jackie", "Stewart", "UK", 99, 27));
racers.Add(new Racer("Emerson", "Fittipaldi", "Brazil", 143, 14));
racers.Add(new Racer("James", "Hunt", "UK", 91, 10));
racers.Add(new Racer("Mario", "Andretti", "USA", 128, 12));
racers.Add(new Racer("Jody", "Scheckter", "South Africa", 112, 10));
racers.Add(new Racer("Alan", "Jones", "Australia", 115, 12));
racers.Add(new Racer("Keke", "Rosberg", "Finland", 114, 5));
racers.Add(new Racer("Niki", "Lauda", "Austria", 170, 25));
racers.Add(new Racer("Nelson", "Piquet", "Brazil", 204, 23));
racers.Add(new Racer("Ayrton", "Senna", "Brazil", 161, 41));
racers.Add(new Racer("Nigel", "Mansell", "UK", 187, 31));
racers.Add(new Racer("Alain", "Prost", "France", 197, 51));
racers.Add(new Racer("Damon", "Hill", "UK", 114, 22));
racers.Add(new Racer("Jacques", "Villeneuve", "Canada", 165, 11));
racers.Add(new Racer("Mika", "Hakkinen", "Finland", 160, 20));
racers.Add(new Racer("Michael", "Schumacher", "Germany", 250, 91));
racers.Add(new Racer("Fernando", "Alonso", "Spain", 88, 15));
racers.Add(new Racer("Kimi", "Räikkönen", "Finland", 122, 15));
return racers;
}
}
}
6 个解决方案
#1
这是设计者考虑的问题,返回接口可能更具有灵活性。
#2
接口更规范一些
适合大型的开发
适合大型的开发
#4
实际上是返回继承该接口的对象
提高扩展性,耦合性。
提高扩展性,耦合性。
#5
面向对象思想的一个最重要的原则就是:面向接口编程。接口定义抽象规则方便代码重用、可扩充性
#6
我觉得意义不大, 如果使用数据绑定, 需要使用ObservableCollection才能正常工作, 你返回一个IList, 你说我到底需要再次包装一次集合呢? 还是推测你返回的就是ObservableCollection? 直接返回ObservableCollection更省事。 不见得跟ObservableCollection耦合就会让程序变得难以修改。
#1
这是设计者考虑的问题,返回接口可能更具有灵活性。
#2
接口更规范一些
适合大型的开发
适合大型的开发
#3
#4
实际上是返回继承该接口的对象
提高扩展性,耦合性。
提高扩展性,耦合性。
#5
面向对象思想的一个最重要的原则就是:面向接口编程。接口定义抽象规则方便代码重用、可扩充性
#6
我觉得意义不大, 如果使用数据绑定, 需要使用ObservableCollection才能正常工作, 你返回一个IList, 你说我到底需要再次包装一次集合呢? 还是推测你返回的就是ObservableCollection? 直接返回ObservableCollection更省事。 不见得跟ObservableCollection耦合就会让程序变得难以修改。