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 892355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:02:29+00:00 2026-05-15T14:02:29+00:00

Say you have an API that is not accessible to change: List<LegacyObject> getImportantThingFromDatabase(Criteria c);

  • 0

Say you have an API that is not accessible to change:

List<LegacyObject> getImportantThingFromDatabase(Criteria c);

Imaging Legacy Object has a ton of fields and you want to extend it to make getting at certain information easier:

class ImprovedLegacyObject extends LegacyObject {
   String getSomeFieldThatUsuallyRequiresIteratorsAndAllSortsOfCrap() {
       //cool code that makes things easier goes here
   }
}

However, you can’t just cast to your ImprovedLegacyObject, even though the fields are all the same and you haven’t changed any of the underlying code, you’ve only added to it so that code that uses LegacyObject still works, but new code is easier to write.

Is it possible to have some easy way to convert LegacyObject to ImprovedLegacyObject without recreating all of the fields, or accessors? It should be a fast opperation too, I konw you could perform something by using reflections to copy all properties, but I don’t think that would be fast enough when doing so to masses of LegacyObjects

EDIT: Is there anything you could do with static methods? To decorate an existing object?

  • 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-15T14:02:30+00:00Added an answer on May 15, 2026 at 2:02 pm

    You would have to perform the copying yourself. You can either have a constructor that does this (called a copy constructor):

    public ImprovedLegacyObject(LegacyObject legacyObject) {        
      ...
      //copy stuff over
    
      this.someField = legacyObject.getSomeField();
      this.anotherField = legacyObject.getAnotherField();
      ...
    }
    

    or you can have a static factory method that returns an ImprovedLegacyObject

    public static ImprovedLegacyObject create(LegacyObject legacyObject) {
      ...
      //copy stuff over
      ...
      return improvedLegacyObject;
    }
    

    If you’re planning on extending this behavior to other legacy objects, then you should create an interface

    public interface CoolNewCodeInterface {
    
       public String getSomeFieldThatUsuallyRequiresIteratorsAndAllSortsOfCrap() {
    
       }
    
       public String getSomeFieldInAReallyCoolWay() {
    
       }
    }
    

    Then your ImprovedLegacyObject would look like this:

    public ImprovedLegacyObject extends LegacyObject implements CoolNewCodeInterface {
    
      //implement methods from interface
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a REST API in java, and it supports responses that are
How to ensure that we are not using latest SDK API? lets say you
Let's say that you have to implement some functionality that is not trivial (it
Say you have a Windows Mobile 6.0 phone that also has a GPS receiver.
We have REST API that we want only our domain has access to and
Let say I have two methods in MVC 4 Web API controller: public IQueryable<A>
I'm trying to compile many files using the Compiler API. Say I have a
Say I have an ASMX web service, MyService. The service has a method, MyMethod.
Let's say I have: vector<T *> vect; I know it's not the obvious way
Let's say I have the URI for a RESTful or other contract-less API. Is

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.