Tinus Tate
Tinus Tate

Reputation: 2375

Reusing component tree in OSGI bundle?

Is there a best practice when it comes to including UI's in an OSGI bundle and reusing this UI in other bundles?

I for example have an custom component tree where every component extends IComponent. For example a inventory field:

InventoryField extends BaseInventoryField
BaseInventoryField extends GridField
GridField extends BaseComponent
BaseComponent implements IComponent

This way i prevent code duplication, if i don't do it like this i have to put the code from BaseComponent, GridField and BaseInventoryField in the InventoryField class. This creates a lot of maintenance and code duplication when something changes and you have a lot of components.

I know one shouldn't extend class from another bundle (eclipse gives me "is not API" warning). But i can't put everything in 1 bundle, cause other bundles must be able to create a GUI (without recreating the entire component tree in the bundle).

Is there a solution for this kind of problem?

Upvotes: 0

Views: 105

Answers (1)

Tassos Bassoukos
Tassos Bassoukos

Reputation: 16152

You definitely can and should extend classes from another bundle, and OSGi will not prevent you doing this. However, the implementation of these classes is now part of the bundle's public API, and you will need to keep track of API changes. It's a tighter coupling than implementing an interface.

Eclipse helps you keep track of API changes, look up the documentation on API baselines.

Upvotes: 2

Related Questions