Suggested Field and Manager Code Structure

public class MyField extends Field implements StyleField {

    /*
     *
     * first comes the logger: private static final
     *
     */

    private static final Logger log = Logger.getLogger( MyField.class );

    /*
     *
     * second comes the constants: uppercase names
     *
     */

    private static final String CONSTANT = "MyConstant";

    /*
     *
     * singleton components
     *
     */

    private static final MyField myself;

    public static MyField instance() {

        if ( myself == null ) {
            
            synchronized (MyField.class) {
              
                if ( myself == null ) {
                    
                    myself = new MyField();
                }
            }
        }
    }

    /*
     *
     * group similar instance variables
     *
     */
    
    private int alphabetCount;
    private int alphabetIndex;
    private String alphabetText;

    private int fruitApple;
    private int fruitOrange;
    private int fruitSelection;

    // the style manager is the last
    private StyleManager styleManager;

    /*
     *
     * constructors should pass on to the next constructor to reduce redundancies
     *
     */

    public MyField() {

        this( null );
    }

    public MyField( String text ) {

        this( text, 0 );
    }

    public MyField( String text, long style ) {

        super( text, style  );

        [...]

        applyComputedStyle();
    }


    /*
     *
     * abstract functions are easier to find if located under the constructor
     *
     */

    protected abstract void getSomething();

    /*
     *
     * suggested method ordering
     *
     */

    protected void onClose();

    public int getPreferredWidth();

    public int getPreferredHeight();

    public Field getLeafFieldWithFocus();

    public boolean isFocusable();

    protected void onInitialize();

    protected void onLoading();

    protected void onUnloading();

    protected void onDisplay();

    protected void onUndisplay();

    protected void onFocus();

    protected void onUnfocus();

    protected void onOrientationChange();

    protected void onTouchEvent();

    protected void trackWheelClick();

    protected void moveFocus();

    protected void drawFocus();

    // This method will be called from RIM's undocumented paintBackground(Graphics).
    // It should not be called from paint()
    protected void paintBackground( Graphics graphics, int width, int height );

    protected void paint( Graphics graphics );

    protected void layout( int width, int height );

    protected void makeMenu( Menu menu, int instance );

    /*
     *
     * next come the inner classes
     *
     */

    private class MyEditField extends EditField {

        [...]
    }

    private class SomeAction extends Action {

        [...]
    }

    /*
     *
     * style functions
     *
     */

    public void applyComputedStyle();

    // RIM's applyTheme() functions should below applyComputedStyle()
    public void applyTheme();

    public StyleManager getStyleManager();

    private void setStyleManager( StyleManager styleManager );

    /*
     *
     * last are the getters and setters
     *
     */

    private int getAlphabetIndex();

    private void setAlphabetIndex( int alphabetIndex );

    [...]
}
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

© 2011 Metova, Inc.