Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7584907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:02:28+00:00 2026-05-30T19:02:28+00:00

I am looking for some best practices/patterns to transform objects from one to another.

  • 0

I am looking for some best practices/patterns to transform objects from one to another. I load the data from DB using DAO to create my domain objects. In my application I need to transform into a different object that acts as an input to another module.
For example, the customer is the domain object which holds a list of orders. I need to transform this into a object customerorder.

Public class Customer {
   String customerid
   List<Order> orders
}

Public class Order {
   Integer id
   Date orderDate
}

/** Transformed objects **/
public class CustomerOrder {
   string customerid
   Integer orderid
}

Currently I have an interface CustomerDTO which has a method to return a list of CustomerOrder objects and a concrete class implementing the interface

Public interface CustomerDTO {
   List<CustomerOrder> getData(Date date)
}

Public class CustomerDTOImpl implements CustomerDTO {
   Private Customer customer
   Public CustomerDTOImpl(Customer customer) {
      this.customer = customer
   }

   Public List<CustomerOrder> getData(Date date) {
       ..... Code to loop through orders and create and return a list with matching order dates
   }
}

For simple, transformations I don’t need a DTO class but my transdormations are very complex and I would like to keep the transformation logic separate for different objects.
Initially I had a transformer class which just loops through all the objects and create transformed objects but I don’t think that was a good design and thought of this DTO. But I believe there are better ways to do it.

Also I need to be able to use the DTO pattern on several objects. In this Customer was just one such object? I have 20 like diffent objects that I need to transform into their respective transformed objects.

Any thoughts on best practices and pattern would be very useful. Also is there any generics I could use to scale them better.

Thanks
Javid

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:02:29+00:00Added an answer on May 30, 2026 at 7:02 pm

    You need to have the object extend or implement another object so that you can cast them as different kinds of objects. I suggest looking into Polymorphism to do this. The name sounds scary, but it’s no big deal

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for some best practices when using Spring 3 annotations . I'm currently
I recently spent some time looking for best practices on preventing browsers from caching
I'm looking to transfer some data from a multi-million row table into another table.
I'm looking for some good overviews of best practices and common patterns for enabling
I'm looking for some Best Practices for automating the deployment of Stored Procedures/Views/Functions/Table changes
Looking for some resources on SOA / BPEL best practices. Specially BPEL.
I am looking for some good links with best practices and sample code on
We're looking at CouchdDB for a CMS-ish application. What are some common patterns, best
[Disclaimer: I'm ASP.NET MVC Developer] Hi, I'm looking for some best practices with implementing
Looking for some best practices of UI list on iPhone which has item add/modify/delete

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.