featured_image

  1. Overview of the Refactoring process
  2. Identify and Group your Access Modifiers
  3. Choose Wise Variable Names, Prefixes and Suffixes
  4. Sort each Access Modifier Groups Alphabetically
  5. **View All**

Group each Access Modifiers together

This first step is crucial to make the remaining steps a breeze. By sorting your variables by their access modifiers, you will gain more advantage when it comes to indenting, renaming, and navigating throughout the code using only your keyboard.

public static const firingSpeed:int;
private static const firingInterval:int;

public static var shots:Array;

private var speed:int;
private var shotsfired:int;
private var angle:Number;
private var lives:int;
private var weapon:Weapon;

public var score:int;
public var upgrades:Array;

Identify your Variables and Constants by Access Modifiers

The next step helps to create a contrast between your ‘private’  and ‘public’  variables & constants. This may vary by programming language or company standards, but generally (and preferably) it is a good idea to:

– Prefix private  variables and constants with an underscore ‘_’ .
– Write public  and private  variables in camelCasing .
– Write constants in UPPER_CASE  and separate each words with an underscore ‘_’ .
– Put static  variables and constants at the top of your class.
– Put the static  keyword following after  the access modifiers (should be the second word).

Following the steps above we should arrive to something like this:

public static const FIRING_SPEED:int;
private static const _FIRING_INTERVAL:int;

public static var shots:Array;

private var _speed:int;
private var _shotsFired:int;
private var _angle:Number;
private var _lives:int;
private var _weapon:Weapon;

public var score:int;
public var upgrades:Array;

Following this procedure will greatly improve the distinction between which variables are externally or internally available throughout the Class method bodies.

On the next page, we will see how to make the variable names more practical and more meaningful.

  1. Overview of the Refactoring process
  2. Identify and Group your Access Modifiers
  3. Choose Wise Variable Names, Prefixes and Suffixes
  4. Sort each Access Modifier Groups Alphabetically
  5. **View All**