简体   繁体   中英

Java class filter to load same class of different versions when class referred in custom loader?

To illustrate the scenario, I have a class called com.test.A and the same class would be modified by different users (eg: DEV1 & DEV2) but they modify their respective classes, eg: com.test.DEV1.A , com.test.DEV2.A

If I use custom loader and load class A, is there any possibility that i can filter the reference of A to DEV1.A or DEV2.A based on some condition?

Without further knowledge of the problem I would say you are trying to solve this problem in the wrong place.

This looks more like a branching problem, that should be solved in the configuration management level, using the features that your SCM gives you. Please have a look at this article on how to handle properly different parallel developments https://thedailywtf.com/articles/Source-Control-Done-Right

The tone is quite accessible and I have used it with success in order to introduce branching to teams, I hope you enjoy it

Class A {
    methodForUser1(params);
    methodForUser2(params);
    ....
    wrapperMethod(params) {
        if (context.user.equals(user1)) 
            methodForUser1(params);
        else if (context.user.equals(user2))
            methodForUser2(params)
        ....
    }
}

Now every user only have to call wrapperMethod and it will in turn delegate to the right method you have for the user in context.

This is brute way of doing it. Additionally, you can load the method using reflection.

Another approach could be what @Jorge_B is suggesting in another answer (maintaining different CI pipelines)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM