Jul 03 2008
Advantage of using Static classes for constants
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.