0

I'm intending to extend & alter an opensource library (LIB_A), which is itself composed of other libraries which have been modified for it's release.
My modifications are probably to be made to all of the libraries.

What is the best way to make subsequent importing of LIB_A into my library as painless as possible when new features are added/bugs are squished, without creating integration issues?

I was thinking of having my library sublass the classes I want to change, and override methods I want to change, but can't figure out if this is possible. The reasoning here is that I might only modify two methods in each class, so that when LIB_A bugs are fixed, if they're not in my modified methods - there is no collision, and I take advantage of the updates for free. If they are in the same method, there's no way around that, which I accept.

If I just copy the whole LIB_A, then I'll have to laboriously go through every file with a diff to see what has been changed, and then incorporate the updates. There must be an established way of doing this?

Is a source repository (local or otherwise) with it's associated check-in and diff behaviour the accepted method?

Thanks


EDIT: This SO question is asking exactly the same thing..

Community
  • 1
  • 1
DefenestrationDay
  • 3,712
  • 2
  • 33
  • 61
  • Sure, but I'm not worried about hosting or getting the source; I want to know the method of writing my code so that subsequent changes to the donor library don't break all(/too many of) my modifications.. – DefenestrationDay Apr 08 '11 at 04:09
  • It completely depends on the changes - can you be more specific about the sorts of changes you need to make? – Justin Apr 08 '11 at 06:15
  • Well, i'll replace some methods of any/all libraries with behaviour I prefer; properties will change; some methods in LIB_A should use different objects that will exist only in my extended library, but be otherwise the same.. Is this what you mean? Basically LIB_A is a great start on what I need, but I need to change it quite a bit. I would like to take advantage of any subsequent bug-fixes in LIB_A, also.. – DefenestrationDay Apr 08 '11 at 06:27

1 Answers1

1

Well, you said it. If you can do it by subclassing, then by all means this is the simplest method.

The problem is that you not always can do it just via subclassing -- e.g. when you need to change a sealed or private method, change other non-virtual methods or properties etc. In this case, there is nothing you can do except to either (1) copy the code and create your own version, (2) modify the code such that those methods/properties are virtual and public -- but make sure it doesn't break anything elsewhere.

Even if you can subclass it, and the new version of the library does not touch the few methods that you overrode, you still have to test your changes fully agian, because your new code may depend on certain implementation details that the new version changed. Of course, the vendor of the library will have modified those few methods for the new version, but your version won't change. So the best way is to do a diff of the vendor's new version of your overridden methods with the old version to detect whether you need to change something in your own version as well.

Stephen Chung
  • 14,497
  • 1
  • 35
  • 48