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

  • SEARCH
  • Home
  • 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 9003417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:42:34+00:00 2026-06-16T00:42:34+00:00

This is not the first time that I’ve found myself in a situation in

  • 0

This is not the first time that I’ve found myself in a situation in which I have to adapt two objects with almost the same data, for example:

User.java  (Object returned from another library)
private String name;
private String surname;
private String email;
private String telephone;
...
getters and setters();
constructor();

MyUser.java
private String name;
private String surname;
private String email;
private String telephone;
...
getters and setters();
constructor();

I usually create a method to convert one object into another one, like this:

 User m1 = new User();
 MyUser m2 = new MyUser();
 m2.setName(m1.getName());
 m2.setsurmame(m1.getsurname());

…and so on…

Does anybody know a different way to do this kind of stuff?

  • 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-06-16T00:42:35+00:00Added an answer on June 16, 2026 at 12:42 am

    Use Object Composition For objects that you create using the other library, create an instance of ExternalUser. But if you want to create them locally, create a BrandNewUser. Then you can just treat them the same way, with one version using the pass-through composition methods, and the ones created by your code using your own internal implementation.

    You can create your object like this:

    public interface MyUser {
      // all the methods you need
      String getSurname();
    }
    
    public class ExternalUser implements MyUser {
      private User _user;
      private ExternalUser() { }
      public ExternalUser(User u) {
        this._user = u;
      }
      public String getSurname() {
        return _user.getSurname();
      }
    }
    
    public class BrandNewUser implements MyUser {
      private String _surname;
      public ExternalUser(String name, String surname) {
        this._surname = surname;
      }
      public String getSurname() {
        return _surname;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that this is not the first time a question about this issue
I'm developing a liferay portlet. This is not my first time doing that, but
This is the first time that I have attempted to add some localization into
This is not the first time I have used databases using the C# in
This is my first time working with file i/o in java, and it's not
First of all i have to clear few things 1.This is not spam group
It's not the first time that i install wordpress on a linux hosting BUT
This is not the first time I've run into this, but here's a concrete
This is the first time that this error has come up. I am using
This is the first time that I'm doing this, so I need a little

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.