When to use Import-Package and Require-Bundle in Eclipse Plugin?
The OSGi way is to use Import-Package, as it specifically decouples the package from the bundle that provides it.
Require-Bundle:
Require-Bundle:
- Bundles can be re-exported
- Gives you access to all exports of the bundle, regardless of what they are, and regardless of whether you need them.
- Specifies the explicit bundle (and version) to use. If a required bundle needs to be refactored and a package moved elsewhere, then dependents will need changes to their MANIFEST.MF file.
- Loose coupling, only the package (and version) is specified and the run-time finds the required bundle.
- Actual implementations can be swapped out
- Dependent packages can be moved to different bundles by the package owner
- But requires more metadata to be maintained (i.e: each package name) at lower levels of granularity
In my view we should below approach in using Import Package or Require-Bundle
Interface <=> Import-Package
Implementation class <=> Import-Bundle/Require-Bundle
Comments
Post a Comment