質問

I am currently writing an Android app which used a piece of open-source code (it is a java class) on Github.

As development of the app go by, I now want to add some application-specified function to the class. Not wanting to modify the original class (since it's open sourced), I thought of extending the class and modifying the extended one. However, there are a bunch of private methods and variables in the original class, making inheritance do not work.

What is the recommended workaround for this situation?

役に立ちましたか?

解決

Wrap the class as part of your own API

If you really have to modify the source, you can always fork the project on github, and make your modifications to the source as you see fit. But I think this would be preferred:

public class OpenClassThatIsntMine {
  // Bunch of their code
}
class MyClass {
  private OpenClassThatIsntMine foobar;
  // My code, which "extends" the functionality of the open source class.
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top