Browsing All Posts filed under »Examples«

Design Patterns: Refactoring an If/Then/Else State Handler using the State Pattern

August 1, 2011

0

Lets consider you wrote this code to save files either locally or over a network connection (the values in capitals are Constants used in your code instead of hard coded values): class MyFile() { // Set our starting position var dataState=DATA_STATE_UNCHANGED; var fileSaveState=FILE_SAVESTATE_UNSAVED; // Store our data binaryData:BinaryData=new BinaryData();  public method saveFile() {    if(dataState==DATA_STATE_UNCHANGED) […]