Imagine you have a library which requires some locale specific operations. We don’t want to create separate bundles for each platform, because much of the code is platform independent, and thus would have to be duplicated. One way to solve above problem is to isolate the platform independent code into its own bundle (let’s call this bundle A), and making separate bundles for the platform specific portion Pp.

Unfortunately this separation is not always easy to achieve, because the platform-specific bundles Pp depend on bundle A. We can export packages from bundle A but then they will be exposed to other bundles too which we might not want or in this case we don’t want any other bundles, except Pp, to see the bundle A exports.

The solution to above problem statement is the use of bundle fragments. Convert Pp into bundle fragment and link it to the host bundle A. In OSGi world, fragment bundles are technically incomplete bundles and their existence depends completely on host bundles because at runtime the fragment bundles are merged into classpath of host bundles.

Other use cases of fragments in AEM implementation can be when you have to develop code that runs for multiple platforms. Where multiple platforms can be fragment bundles and the code can be under its own host bundle.