Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Translator Pattern

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.

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?

like image 269
Larry Watanabe Avatar asked Dec 22 '09 22:12

Larry Watanabe


People also ask

What is interpreter design pattern used for?

Interpreter design pattern is one of the behavioral design pattern. Interpreter pattern is used to defines a grammatical representation for a language and provides an interpreter to deal with this grammar. This pattern involves implementing an expression interface which tells to interpret a particular context.

What is a message translator?

The Message Translator is the messaging equivalent of the Adapter pattern described in [GoF]. An adapter converts the interface of a component into a another interface so it can be used in a different context. ...

What is design pattern in Java?

Design patterns represent the best practices used by experienced object-oriented software developers. Design patterns are solutions to general problems that software developers faced during software development.

What is Visitor pattern in Java?

Visitor pattern is used when we have to perform an operation on a group of similar kind of Objects. With the help of visitor pattern, we can move the operational logic from the objects to another class. For example, think of a Shopping cart where we can add different type of items (Elements).


1 Answers

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.

like image 109
GrayWizardx Avatar answered Sep 18 '22 18:09

GrayWizardx