multithreading - Decoupling in threaded environment java -


i facing decoupling problem. let me explain example:

say have different classes uses jar. jar keeps on getting updated , need update our system along too. if there slight change in jar have make changes every class, decided decouple it. these classes call jar classes in such way make object of it, set flag , on basis of derive results. hence every object has own importance in every method.

let me explain simple example.

say have class x

class x {   base base;   public int getcalresult(int a, int b) {      base = new base();      base.seta(a);      base.setb(b);      return base.getresult();   }    public int getcalresult2(int a, int b, int c) {      base = new base();      base.seta(a);      base.setb(b);      base.setc(c);      return base.getresult();   } }  class base { legacy class inside jar can't change   int a, b, c, d;   public seta(int a) {     this.a = a;   }   public getresult() {     return + b + c + d;   } } 

how decouple sort of structure , make thread safe @ same time. pointers ? design patterns ?

i want calls jar must maintained in single class, in case if there change in jar have deal single class , not of them

what did

introduced baseproxy

public class baseproxy {   base b;   public static newinstance() {     b = new base();   }    public static setabcd(int a, int b) {     b.seta(a);     b.setb(b);   } }  class x {       public int getcalresult(int a, int b) {          baseproxy.newinstance();          baseproxy.setab(a,b);          return baseproxy.getresult();  }    public int getcalresult2(int a, int b, int c) {      baseproxy.newinstance();      baseproxy.setabc(a,b,c);      return baseproxy.getresult();   } } 

this have worked in single threaded env not in mutli. need suggestion on this. other better design, sure there is.

few things not clear (or not ideal) 1. when say, legacy class in jar updated, change existing prototype or adds new functionality ? if keep updating definition in trouble.

to around this, 1 way extract interface out of legacy class , define delegate implementing (place outside calling code) , use in calling code reduce direct dependency. delegate should talk legacy class.

also, whenever legacy class changes, delegate side need update (unless there complete turnaround in called functions)


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -