The real voyage of discovery consists not in seeking new lands but seeing with new eyes.
                                - Marcel Proust
 
Поиск
Поиск

 
 
Меню навигации
Меню навигации
 
 
Проекты
Проекты
 
 
 
 
Size_box_tl   Size_box_tr
 
Unfortunately, there is no translation for this page. We have redirected you to the english version of the site. We are sorry for any inconvenience caused...

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.

 

Эта страница была обновлена: 05/11/2009 07:44


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