R
Roland J Rankin Jr
Shortest possible explanation..
I'm using a jar I didn't write and have legal issues preventing me from
decompiling and recompiling as I see fit. Not to mention compatibility
and maintenance issues.
In general, I create an instance of their master object witch auto
magically hides all the networking, message encoding/decoding, and
transforms everything into an Events that I register as an event
listener to.
The particular event I listen fires multiple times, but all the data
that distinguishes instance X from instance y is hidden behind protected
methods.
e.g.
public class SkillGroupEvent extends Event
{
// blah
protected int getSkillGroupId();
protected String getSkillGroupName();
protected long getSkillGroupState();
// more blah
}
Now, I am trying to figure out what is the best way in the long term to
actually use (read get to) this data.
1. I could Decompile changed protected to public and call it a day. But
that's not an option for legal reasons.Plus it makes a head ache with
new versions and any coders that have to tread in my footsteps are not
going to like it one bit.
... Not going this way.
2. I could write my own SkillGroupEvent and hide the original by making
sure that mine was found on the class path before theirs. However this
seems a very brittle solution. (This would of course include solutions
revolving around custom class loaders..)Causing Long term issues with
compatibility and class path maintenance. (e.g what if they update their
package and my code no longer has all the correct internals, or methods)
.... Not going this way.
3. I could Extend their class. But since I'm not the one creating the
Event instance. I couldn't force their code to create an instance of my
class. I'd be stuck creating a constructor that Took an instance of
their Object and returned an instance of my object. (essentially a deep
copy constructor) That was basically a thin wrapper to expose the
protected data to my package. I lose the ability to extend from a common
class. Not a major issue, since their events don't correspond to my Base
classes anyway.
This solution seems the unfortunate choice, but some how feels ..
*thinks of good word* wasteful(?) Since now I need to Build an object to
expose their data and another object to act on the data. Three objects
versus two. (Data, data parser, data actor instead of Data, Data actor.)
I just some how dirty using this method, esp since I'll be building
roughly a thousand of these per minute, possibly much much more.
Probably stuck with this solution.
4. I could Write a class into their package that contained an instance
of their object and exposed the data, or Move my Event listener into
their package. Since I'm not extending their class I'm free to extend my
own classes. Which makes a maintenance issue for me. Long Term I'd like
to keep my code in my package. This feels like a dirty kludge. Works but
wrong at a fundamental/philosophical level. Since anyone that came after
me would now think their stock package supplied more functionality than
it actually does.
.... Not going this way.
So anyone have any alternatives? am I correct in thinking extending
their class with a sole constructor that takes an instance of their
class is the only way to go about this?
I'm using a jar I didn't write and have legal issues preventing me from
decompiling and recompiling as I see fit. Not to mention compatibility
and maintenance issues.
In general, I create an instance of their master object witch auto
magically hides all the networking, message encoding/decoding, and
transforms everything into an Events that I register as an event
listener to.
The particular event I listen fires multiple times, but all the data
that distinguishes instance X from instance y is hidden behind protected
methods.
e.g.
public class SkillGroupEvent extends Event
{
// blah
protected int getSkillGroupId();
protected String getSkillGroupName();
protected long getSkillGroupState();
// more blah
}
Now, I am trying to figure out what is the best way in the long term to
actually use (read get to) this data.
1. I could Decompile changed protected to public and call it a day. But
that's not an option for legal reasons.Plus it makes a head ache with
new versions and any coders that have to tread in my footsteps are not
going to like it one bit.
... Not going this way.
2. I could write my own SkillGroupEvent and hide the original by making
sure that mine was found on the class path before theirs. However this
seems a very brittle solution. (This would of course include solutions
revolving around custom class loaders..)Causing Long term issues with
compatibility and class path maintenance. (e.g what if they update their
package and my code no longer has all the correct internals, or methods)
.... Not going this way.
3. I could Extend their class. But since I'm not the one creating the
Event instance. I couldn't force their code to create an instance of my
class. I'd be stuck creating a constructor that Took an instance of
their Object and returned an instance of my object. (essentially a deep
copy constructor) That was basically a thin wrapper to expose the
protected data to my package. I lose the ability to extend from a common
class. Not a major issue, since their events don't correspond to my Base
classes anyway.
This solution seems the unfortunate choice, but some how feels ..
*thinks of good word* wasteful(?) Since now I need to Build an object to
expose their data and another object to act on the data. Three objects
versus two. (Data, data parser, data actor instead of Data, Data actor.)
I just some how dirty using this method, esp since I'll be building
roughly a thousand of these per minute, possibly much much more.
Probably stuck with this solution.
4. I could Write a class into their package that contained an instance
of their object and exposed the data, or Move my Event listener into
their package. Since I'm not extending their class I'm free to extend my
own classes. Which makes a maintenance issue for me. Long Term I'd like
to keep my code in my package. This feels like a dirty kludge. Works but
wrong at a fundamental/philosophical level. Since anyone that came after
me would now think their stock package supplied more functionality than
it actually does.
.... Not going this way.
So anyone have any alternatives? am I correct in thinking extending
their class with a sole constructor that takes an instance of their
class is the only way to go about this?