Once a programmer had a problem. He thought he could solve it with a regular expression. Now he had two problems.
                    - Anonymous
 
Search
Search

 
 
Navigation menu
Navigation menu
 
 
 
 
Size_box_tl   Size_box_tr
 

What did we start from?

 

Here is a sample code of two classes in java. One is inherited from another with some tricky overriding of a method:

The Parent:

public abstract class AbstractStatePolicyWorkerImpl extends AbstractStatePolicyImpl {

...

    protected StateDeterminer getWorker(final String containerName) {
        StateWorker stateWorker = getWorkerMap().get(containerName);
        if (stateWorker == null) {
            return getDefaultWorker();
        }
        return stateWorker;
    }
    
    protected abstract StateWorker getDefaultWorker();

...

}

The Child:

public class ProductStatePolicy extends AbstractStatePolicyWorkerImpl {

...

    @Override
    protected StateWorker getWorker(final String containerName) {
        StateWorker worker = super.getWorker(containerName);
        if (worker == null) {
            worker = new DefaultAuthorizationWorker();
        }
        return Worker;
    }



    @Override
    protected StateWorker getDefaultWorker() {
        return new DefaultEditableWorker();
    }

...

}

 

Today's lesson:

Whenever you use Template pattern be sure to prohibit overriding of the temple methods such as #getWorker() in the code above. This will allow avoiding IDD comming into your code. In java this could have been accomplished by placing final modifier onto method.

 



© Inspire Software, Denys Pavlov, 2005-2012
© Inspire Software, Denys Pavlov, 2005-2012
 
Size_box_bl   Size_box_br