Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #9081

Re: Enum mixin?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From markspace <-@.>
Newsgroups comp.lang.java.programmer
Subject Re: Enum mixin?
Date Fri, 21 Oct 2011 16:16:00 -0700
Organization A noiseless patient Spider
Lines 60
Message-ID <j7sufj$ekp$1@dont-email.me> (permalink)
References <WsudnUpWT_V6fDzTnZ2dnUVZ_vCdnZ2d@speakeasy.net> <9ge71qFkv0U1@mid.individual.net>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Fri, 21 Oct 2011 23:16:04 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="XjIWM99mD7Ijfdu600oVPA"; logging-data="15001"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18wd5mhMEGbxdsUC7WpVACaKhgiEBFOATY="
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1
In-Reply-To <9ge71qFkv0U1@mid.individual.net>
Cancel-Lock sha1:/uPj08AjQXBjAoLb2J38jE4ZnDE=
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:9081

Show key headers only | View raw


On 10/21/2011 2:37 PM, Robert Klemme wrote:

> On 21.10.2011 23:19, A. W. Dunstan wrote:
>> I'm ok with leaving it the way it is, but does anyone know of a better
>> approach? Preferably one that's not so complex that it's worse than my
>> current state of affairs?

> I don't think it gets any better. Even if you go away from enums and
> create an abstract base class etc. you'll have to do the typing for the
> values plus you need to take care of serialization etc.


I would have thought that an abstract base class would get you what you 
need.  Maybe I'm overlooking something.  The second class here seems to 
remove a lot of boilerplate, esp considering my IDE will write the 
constructor for me (since it's the only one available).


package quicktest;

import java.io.Serializable;

public abstract class AbstactEnum implements Serializable {

    private final int value;
    private final String name;

    public AbstactEnum(int value, String name) {
       this.value = value;
       this.name = name;
    }

    public String getName() {
       return name;
    }

    public int getValue() {
       return value;
    }
}

final class CloudModel extends AbstactEnum {

    /*
     * value   meaning
    -----   ---------
    0       no clouds
    1       cumulus
    2       altostratus
    18      cirrus */
    public static final CloudModel NONE = new CloudModel(0, "No Clouds");
    public static final CloudModel CUMULUS = new CloudModel(1, "Cumulus");
    public static final CloudModel ALTOSTRATUS = new CloudModel(2, 
"Altostratus");
    public static final CloudModel CIRRUS = new CloudModel(18, "Cirrus");

    public CloudModel(int value, String name) {
       super(value, name);
    }
}

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Enum mixin? "A. W. Dunstan" <no@spam.thanks> - 2011-10-21 17:19 -0400
  Re: Enum mixin? Robert Klemme <shortcutter@googlemail.com> - 2011-10-21 23:37 +0200
    Re: Enum mixin? markspace <-@.> - 2011-10-21 16:16 -0700
      Re: Enum mixin? Robert Klemme <shortcutter@googlemail.com> - 2011-10-23 11:44 +0200
        Re: Enum mixin? Lew <lewbloch@gmail.com> - 2011-10-23 08:45 -0700
    Re: Enum mixin? "A. W. Dunstan" <no@spam.thanks> - 2011-10-24 09:23 -0400
  Re: Enum mixin? Roedy Green <see_website@mindprod.com.invalid> - 2011-10-22 18:10 -0700

csiph-web