Note that there are some explanatory texts on larger screens.

plurals
  1. POClass derivation on the fly - Visitor Pattern
    text
    copied!<p>I would like to create visitor pattern in such a way</p> <pre><code>public interface Visitable&lt;T&gt;{ public void accept(T visitor); } public interface SomeBusinessService implements Visitable&lt;SomeVisitor&gt;{ public void mtd1(); public void mtd2(); } public abstract class SomeBusinessBean1 implements SomeBusinessService { public void mtd1(){} public void mtd2(){} } public abstract class SomeBusinessBean2 implements SomeBusinessService { ... } </code></pre> <p>and so on</p> <p>then I would like to create a factory </p> <pre><code>public class SomeBusinessServiceFactory { public SomeBusinessService createService (Class&lt;? extends SomeBusinessService&gt; clazz ){ //do some stuff to create appropriate class derivation on the fly // that will have accept() method implemented } } </code></pre> <p>and I could invoke it in the following way</p> <pre><code>SomeBusinessService service = SomeBusinessServiceFactory.createService(SomeBusinessBean1.class); </code></pre> <p>With this approach I would't have to create comman abstract class for all beans that implement Visitor interface accept() method. </p> <p>This solution could also be used in situations where we would like to have a common behaviour of specific methods depending on service factory per class hierarchy.</p> <p>Is there any way to do that with standard jdk or maybe I need to use external tools like cglib or maybe what I'm saying is rubbish and we can achive that goal in some other way.</p> <p>Tx in advanced</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload