私はしばしば (現時点では) 次のような c# (または vb.net) コードを書くようになります:
someObject.field_1 = doSomething(
anotherObject_1.propertyA,
anotherObject_1.propertyB);
someObject.field_2 = doSomething(
anotherObject_2.propertyA,
anotherObject_2.propertyB);
// some more field in same schema.
someObject.field_X = doSomething(
anotherObject_X.propertyA,
anotherObject_X.propertyB);
編集: anotherObject_1 .. anotherObject_X の型は同じです。someObject と anotherObject は通常、同じ型ではありません。
問題は拡張性と保守性です。新しいフィールドを使用すると、オブジェクトの命名がわずかに異なるだけで、ほぼ同じコードを記述できます。
doSomething(..) でロジックをカプセル化すると、ロジックの冗長性を回避できますが、呼び出しの冗長性は依然として厄介です。
これを回避する方法 (パターンや .Net (4.0) 言語構造など) はありますか?