oop - How to avoid downcasting when trying to extend a Java object -
I get many objects from an external API foo by call i locally I I want to process with a bit of information, so I have a subclass FooSon which adds those additional fields. How can I change all the things that are in my new heritage? Downcasting does not seem to be an option because those objects are not actually FooSon The only solution I have come up with is creating a convert function which is Fu < Strong> takes the object as an argument and then a new FooSon object which is returned to all public / protected values Disadvantages: < Ul> Class Fu does not implement a per constructor or clone operator. I have a fu source code but I would like to avoid changing it to keep it consistent with future releases. Even if this is the only viable option, then I can change the implementation of FU which I want. FooSon can contain a field that is a foo. Then specify only the returned value in that field. You can then create methods in Foshan that give the Fu field your information for the information that you need to get out of Foo.
Comments
Post a Comment