开发者

Is it safe to OSGi export API containing reference to implementation code?

Let's imagine I implement the following:

public enum ExportAPIForOSGi {
    ;
    public static SpecialObject newSpecialObject() {
        return new SpecialObjectImplv1();
    }
}

public abstract class SpecialObject {
    public abstract String specialMethod(String s);
}

public class SpecialObjectImplv1 extends SpecialObject {
    @Override
    public String specialMethod(String s) {
        return "33" + s;
    }
}

Each class is declared in its own separate file. Only ExportAPIForOSGi and SpecialObject are to be OSGi exported.

My question: is it safe to export ExportAPIForOSGi since it contains an explicit reference to implementation code (i.e., SpecialObjectImplv1)? Is the implementation code going to开发者_开发问答 be exposed?

Let's imagine that later, I use SpecialObjectImplv2 in ExportAPIForOSGi instead of v1? Is this going to be an issue?


You need to export the package(s) containing ExportAPIForOSGi and SpecialObject since they are your public API. SpecialObjectImplv1 should be in another package which is not exported. You are then free to change the implementation of newSpecialObject to use another impl class since the impl class is not visible in the signature of the public API.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜