0

In Java, I have some legacy classes (from 3rd party library which I cannot edit) that to not implement any interfaces, but for which I would like to create a mixin.

I have looked at cglib for creating mixins, but this tutorial states that

cglib Mixins allow the combination of several objects into a single object. However, in order to do so, those objects must be backed by interfaces

So does anyone know how to create a mixin of two concrete classes, neither of which implement any interfaces?


I had been thinking about using bytecode generation to automatically extract an interface from a concrete class that I could then just feed into cglib, but I have no idea how to do that either...

1
  • IMO you are better off selectively rewriting or rewriting the legacy classes. Commented Jan 26, 2015 at 9:57

1 Answer 1

2

No need for anything fancy, just a bit of dull donkey work.

Create the interfaces you'd like to program against, then create concrete classes that implement them using the legacy library.

You can now create mixins using cglib if you really want to, but more importantly you can develop your app without making it strongly dependent on the legacy 3rd party library.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.