Design pattern for mapping data fields

design-patterns

I have seen this problem a few times and never can come up with a solution i like.

System A
    Sales Order Entity
        order_id
        created
        line_items_count

System B
    Sales Order Entity
        sales_order_id
        created_At
        num_line_items

The problem is, that sales orders are created in System A – for example an e-commerce website. The sales orders need to be exported and stored in another system, for example a warehouse system – System B. They both store the same data but under different field names.

Is there a design pattern or collection of patterns typically used to solve such problem?

I always end up with an associative array containing the mapped fields – but it feels like there must be a better solution.

In the example above, not only sales orders might require this, also customers, products, inventory levels etc – so a generic pattern would be best.

Best Answer

Though probably not recognised as a design pattern, what you describe would be called a Mapper.
It translates one object into another.
Implementations can be found at AutoMapper.org and at CodeProject.

Related Topic