Results 1 to 8 of 8

Thread: Best practice to solve this problem

  1. #1
    Join Date
    Jul 2005
    Location
    Austria
    Posts
    105

    Default Best practice to solve this problem

    Hi,

    I have different loaders which share a common functionality, implemented in the ExchangerLoader:
    Code:
    public abstract class ExchangerLoader {
        // Declarations
        protected IMapper mapper;
        protected IDocumentHandler docHandler;
        protected String initialProcess = "AKT";
    
        /*
         * DEPENDENCY INJECTIONS
         */
        public void setDocumentHandler(IDocumentHandler docHandler) {
            this.docHandler = docHandler;
        }
    
        public void setInitialProcess(String process) {
            this.initialProcess = process;
        }
    
        public void setDataMapper(IMapper mapper) {
            this.mapper = mapper;
        }
    
        //Some shared methods, which are used by all loaders
    
       //This class must be implement by all derived classes
        public abstract String loadData(String docId, String folder, String type, String viewField);
    Now I've specific loaders:
    - ViewLoader
    - ObjectLoader
    - TreeLoader

    These loaders extend the ExchangeLoader and implements the loadData-Method. The specific loaders also access methods from the ExchangerLoader.
    Code:
        <!-- LOADERS -->
        <bean id="viewLoader" class="com.mycomp.exchanger.loader.ViewLoader">
            <property name="documentHandler">
                <ref bean="documentHandler"/>
            </property>
            <property name="dataMapper">
                <ref bean="mapperService"/>
            </property>
        </bean>
        <bean id="objectLoader" class="com.mycomp.exchanger.loader.ObjectLoader">
            <property name="documentHandler">
                <ref bean="documentHandler"/>
            </property>
            <property name="dataMapper">
                <ref bean="mapperService"/>
            </property>
        </bean>
        <bean id="treeLoader" class="com.mycomp.exchanger.loader.TreeLoader">
            <property name="documentHandler">
                <ref bean="documentHandler"/>
            </property>
            <property name="dataMapper">
                <ref bean="mapperService"/>
            </property>
        </bean>
    The configured loaders are now injected to a service which decides what loader should be used. I think this is an implementation of the Strategy Design pattern. Now my question, as you can see on the declaration above all my loaders need the documentHandler and mapperService. Is there a better way to configure these loaders?

    thank you for your advices

    markus

  2. #2
    Join Date
    Feb 2006
    Location
    Arlington, VA, USA
    Posts
    194

    Default

    Quote Originally Posted by Demo
    Now my question, as you can see on the declaration above all my loaders need the documentHandler and mapperService. Is there a better way to configure these loaders?
    I think you are looking for bean inheritance[1]. Try it and let us know if it works.

    Glen

    [1] http://yan.codehaus.org/Bean+Reusability+Compared

  3. #3
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    Quote Originally Posted by Demo
    Is there a better way to configure these loaders?
    You can specify parent="" for a bean to inherit the definition of the specified bean.

  4. #4
    Join Date
    Jul 2005
    Location
    Austria
    Posts
    105

    Smile It works fine

    I use the configuration posted on the mentioned site http://yan.codehaus.org/Bean+Reusability+Compared

    wow! In the manner of maintaining this is beautiful.

    thanks again, markus

  5. #5
    Join Date
    Dec 2005
    Posts
    269

    Default

    hmm, just took a look at
    http://yan.codehaus.org/Spring,+Pico+and+Nuts+Compared

    the comparison table there is quite funny for example:
    Life cycle:
    Spring: Singleton only,
    Pico: Singleton only,
    Yan: Both singleton and prototype

    nice isnt'it? so, enough of Spring, I'll switch to Yan/Nuts !

  6. #6
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    There are a number of errors in that comparison table

    I couldn't find a way to inform the author though....

  7. #7
    Join Date
    Dec 2005
    Posts
    269

    Default

    I'm just wondering, who would use something like Yan?
    it looks more like a graduating project

  8. #8
    Join Date
    Feb 2005
    Location
    Boston, MA
    Posts
    1,142

    Default

    Quote Originally Posted by Injecteer
    hmm, just took a look at
    http://yan.codehaus.org/Spring,+Pico+and+Nuts+Compared

    the comparison table there is quite funny for example:
    Life cycle:
    Spring: Singleton only,
    Pico: Singleton only,
    Yan: Both singleton and prototype

    nice isnt'it? so, enough of Spring, I'll switch to Yan/Nuts !
    I believe what he's referring to is that prototypes don't participate in the complete Spring lifecycle (no destroy-method). That of course is misleading since prototypes do invoke their init-method.

    As for a contact, its on the Yan home page: Ben Yu
    Bill

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •