6

以前の仕事で、マネージャーは、データを DataTable からオブジェクトに変換するための Translator パターンの使用を提案しました。基本的に、Translator クラスには静的 (つまり、クラス) メソッドしかないため、関数呼び出しの集合体でした。私の最初のアプローチは、DataTable 行を引数として取り、データに対応するインスタンスを作成できる各オブジェクトのコンストラクターを実装することでした。

彼は、Translator クラスは Microsoft によって提案されたものであり、コードのより優れたモジュール性を提供したと述べました。この点はわかりますが、同時に非常に非オブジェクト指向のアプローチのようにも思えます (ビジター パターンにも同様の特徴がありますが)。

このパターンを使用したことがある人はいますか?どう思いますか? 長所と短所?

4

4 に答える 4

5

From C2.Com it appears that the Translator pattern is a non-OOP implementation of the visitor pattern. It notes and the end of the article a few of the drawbacks, including the fact that in OOP semantics it is difficult to express (but not code), in other words it will work fine but may not make a lot of sense if you are using pure OOP for the rest of your code.

于 2009-12-22T23:01:44.763 に答える
0

Maybe I'm missing something, but why not just use linq?

    IEnumerable<Customer> customerQuery =
    from cust in customers
    where cust.City == "London"
    select cust;

foreach (Customer customer in customerQuery)
{
    Console.WriteLine(customer.LastName + ", " + customer.FirstName);
}

Anyway, the TranslatorPattern is about changing the data structure from one representation to another equivalent structure. Here http://c2.com/cgi/wiki?TranslatorPattern is the deeper info on that.

于 2009-12-22T22:58:01.250 に答える