ある日の出来事ですが、出来上がったコードが、今までに無いパターンだったので不思議に思った訳です。
こんなコードでした。
public class Base {
public void LoadData() {
using(var a = this.GetTableAdapter()) a.Fill(this.dataSet);
}
protected Func<BaseTableAdapter> GetTableAdapter;
}
public class AAA : Base {
public AAA() {
this.GetTableAdapter = () => (new AAATableAdapter());
}
}
public class BBB : Base {
public BBB() {
this.GetTableAdapter = () => (new BBBTableAdapter());
}
}
で、妙に思って、よくよく見てみると、普段は以下のように書いていたコードなんだと思います。多分。
public class Base {
public void LoadData() {
using(var a = this.GetTableAdapter()) a.Fill(this.dataSet);
}
protected virtual BaseTableAdapter GetTableAdapter() {}
}
public class AAA : Base {
protected override BaseTableAdapter GetTableAdapter() { return new AAATableAdapter(); }
}
public class BBB : Base {
protected override BaseTableAdapter GetTableAdapter() { return new BBBTableAdapter(); }
}
ってことはアレですか、メソッドを
Override する場面ではラムダ式を使える
ってことになる訳ですか。そうですか。
今更ですか?