翻译模式 [英] Translator Pattern

查看:192
本文介绍了翻译模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在之前的工作中,我的经理建议使用翻译器模式将数据从DataTable转换为对象。基本上,Translator类只有静态(即类)方法,所以它是函数调用的聚合。我的初始方法是为每个对象实现构造函数,该对象可以将DataTable行作为参数,并创建一个与数据对应的实例。

In a previous job, my manager suggested use of a Translator pattern for converting data from a DataTable to objects. Basically, the Translator class had only static (i.e. class) methods so it was an aggregation of function calls. My initial approach was to implement constructors for each object that could take a DataTable row as an argument and create an instance that corresponded to the data.

他说,已被Microsoft提出,提供了更好的代码模块化。我可以看到这一点,但同时它似乎是一种非OO方法(尽管访客模式有类似的特征)。

He said that the Translator class had been suggested by Microsoft, and provided better modularity of code. I can see this point, but at the same time it seems like a very non-OO approach (although the Visitor pattern has similar characteristics).

有没有人用过这种模式,你觉得怎么样?优点和缺点?

Have any of you used this pattern, and what do you think of it? pros and cons?

推荐答案

C2.Com 看来,翻译者模式是访问者模式的非OOP实现。它注意到文章的最后一些缺点,包括在OOP语义中很难表达(但不是代码)的事实,换句话说,它可以正常工作,但是如果你是使用纯OOP代替其余代码。

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.

这篇关于翻译模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆