model -> view tiers and constants

Discussion in 'Java' started by VisionSet, Sep 11, 2003.

  1. VisionSet

    VisionSet Guest

    In my model tier I often have constants declared like this:

    private static final String[] STRING_CONSTANTS = new String[2];
    private static final int CONST_A = 0, CONST_B = 1;
    static {
    STRING_CONSTANTS[CONST_A] = "Eh?";
    STRING_CONSTANTS[CONST_B] = "Bee";
    }

    Then I can give the view tier (jsp) access to the array which it can iterate
    over, using the array index to return selected <option>s.
    This can then be matched up back in the model tier with simple switch
    statement.

    switch(myHttpParam) {
    case CONST_A: // do A stuff
    case CONST_B: // do B stuff
    }

    I can't see how it can be any simpler than this, but have never seen this
    done.

    Any views on this?

    [Chris Smith, you answered a similar question from me a month or so back,
    this is a more concrete example]
     
    VisionSet, Sep 11, 2003
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.