Back Forum Reply New

encapsulation pattern to abstract common logic

what's best encapsulation pattern to use to abstract out common logic.

e.g. have a child class say

Code:
ClassA implements Interface{public void search(Form form){   StringBuffer queryBuilder = new StringBuffer();   queryBuilder .setParam(quot;aquot;, quot;value1quot;);   queryBuilder .setParam(quot;bquot;, quot;value2quot;);   }
}

ClassB implements Interface {publlic void search(Form form){   StringBuffer queryBuilder = new StringBuffer();   queryBuilder .setParam(quot;aquot;, quot;value1quot;);   queryBuilder .setParam(quot;bquot;, quot;value2quot;);}
}
both classes implement same interface. however there is a great amount of common code both search() method use. e.g. building queries (builder variable) and some other similar code. I can abstract out common code in a super class(don't like to code to implementation though) but then I'll have to pass in this StringBuffer(queryBuilder) variable as a parameter to search method (so child class have common things build out and add any more values to it), which will force me to change search() method's signature in interface and violates open closed principle. also can't afford to change search() method signature in interface. what's the best way to achieve this?

Thanks,
¥
Back Forum Reply New