Question

I have created a library which supports an application, however in the newest version of the application the developer has changed the structure without changing the class names.

So version 1 of the application has classX in package A but version 2 has classX in package B. How can I develop my library in a way which allows supporting both of these in the same build?

Edit: My library is dependent on the application, not the other way around.

Was it helpful?

Solution 2

Short answer: You can't.

Real answer: Your library should be able to exist independently of any application that uses it. The purpose of a library is to provide a set of reusable, modular code that you can use in any application. If your library is directly dependent on application classes, then it seems like a redesign should be seriously considered, as your dependencies are backwards. For example, have A.classX and B.classX both implement some interface (or extend some class) that your library provides, then have the application pass instances of those objects, or Class's for those objects, to the library.

If your "library" can't be designed this way then consider integrating it into application code, making it a direct part of the application, and come up with a better team workflow for you, the other developer, and others to work on the same project together.

Quick fix answer: Do not provide backward compatibility, as Jigar Joshi states in his answer.

Bad answer: You could hack a fragile solution together with reflection if you really had to. But please note that the "real answer" is going to last in the long run. You are already seeing the issues with the design you have currently chosen (hence your question), and a reflection based solution isn't going to prevent that from happening again (or even be reliable).

OTHER TIPS

That is a bad decision, if you still want to make it work you need to provide skeleton classes with old structure and delegate calls to new version of class but it would get very dirty

better to not provide backward compatibility if you are firm with the renaming decision

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top