jeudi 7 juillet 2016

Prevent using some APIs of a depending package

We have some code wrapping API of a third-party package, and now we don't want our team members to mistakenly use the third-party package directly, is there any way to prevent it? (Such as add some kind of checking in UT). Example:

Code in a third-party package (so we cannot change it):

class OrigProvider {  
    public static String getSomething() { return sth;}
}

Code in my package (we need to third-party package):

class MyProvider {  
    public static String getSomething() {  
        sth = OrigProvider.getSomething;   
        process(sth);   
        return sth;  
    }  
}

And in our code, if someone incorrectly use OrigProvider.getSomething, our program will be wrong silently, so how to guarantee no one use the OrigProvider.getSomething?

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire