1

I call myConnection.open() from my MainActivity. myConnection is an object of the library class Connection:

public class Connection implements SomeOtherLibraryClass { ... }

providing the function

public void open(){ this.mCurrentConnection = this.mConnectionFactory.createConnection(); }

which invokes another library class:

public class ConnectionFactory { ... }

having the constructor

public ConnectionFactory(){ mInitCommand = "Original Bla"; }

and processing mInitCommand in the createConnection function.

Now I would like to override the content of mInitCommand before being processed in the createConnection function like in this question, but without touching the library classes.


I know that I could create an object of a new class extending ConnectionFactory and overriding the variable, but then I would have to change mConnectionFactory to point to my customized class instead of the original one. Thanks for your help!

Community
  • 1
  • 1
F1iX
  • 823
  • 6
  • 12
  • How is `Connection` instantiated? Can you pass a custom factory? Which library is this? – shmosel May 03 '16 at 00:28
  • That's a bit tricky and I did not deeply understand it yet: `onServiceConnected` I have `myConnection = (ServiceType) service` and `service` get's passed as an IBinder object. I got this from the libraries documentation, which is a closed source library of my company. Unfortunately I don't see how I could pass a custom ConnectionFactory, since the ConnectionFactory gets invoked by the Connection class which I cannot modify. – F1iX May 03 '16 at 18:11
  • We can't really help you use a closed source library unless you're willing to post some of the code or documentation. – shmosel May 03 '16 at 18:21
  • Unfortunately the library is pretty big and I won't be allowed to release it here, therefore I tried to abstract and generalize the question as much as possible. So am I right that there is no trivial way of overriding the last class in a chain and make the other classes use the overridden version without changing them? – F1iX May 04 '16 at 14:02

0 Answers0