Jul 03 2008

Advantage of using Static classes for constants

Published by at 2:45 pm under Flash

Static classes for defining constants, wait what?????. You might have come across classes like StageDisplayState in flash.display package and it doesn’t contain any useful methods except for constants which are used for setting the state of stage. This is not exactly a static class but if you remove all the methods it would be one. 

Why do we need this class when we can set the stage property like this in AS 2,

Stage[“displayState”] = “fullScreen”;

where as in AS 3/Flex its wise to use something like,

Application.application.stage.displayState = StageDisplayState.FULL_SCREEN;

It might seem unnecessary to create an extra class to define variables but its helpful. 

  • A programmer might decide to change the string instead of fullScreen it will be now FullScreen, dumb but it can happen. If it does happen then there won’t be any errors at compile time but you might get run time errors.
  • By same argument as above, if we decide to change StageDisplayState.FULL_SCREEN to StageDisplayState.FULLSCREEN we will get a compile time error and we can fix it.
So its mainly to fix problems during compile time rather than run time the above method is useful. Hope it makes sense. I should probably come up with a more concrete example i suppose.

No responses yet

Trackback URI | Comments RSS

Leave a Reply