Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Loving Enums

Reply
Thread Tools

Loving Enums

 
 
Roedy Green
Guest
Posts: n/a
 
      07-11-2005
Something about enums and I really click.

I'm finding the enum pattern really helps chaotic code that deals with
doing different things in different situations. If I can come up with
some sort of enum to classify the situations, the code becomes
somewhat bulkier, but it is so simple to understand and extend. It
helps clarify for ME just how it all works.

If you have a number of legal and illegal combinations of things, you
can use the enum constructors to describe a set of legal combinations,
then just search the enums to see if your pattern matches or the one
with the best fit.

It then becomes trivial to proofread the list. It is easy to add
methods to each combination to override the usual case. And of course
adding or removing a legal combination becomes a snap, rather than
pruning logic in a dozen places.

The main thing that annoys me with them is, because the enum constants
are implemented as anonymous inner classes, they cannot contain static
variables or methods private to them. Further their constructors
cannot access any statics.
--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/...s_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
Reply With Quote
 
 
 
 
Tim Tyler
Guest
Posts: n/a
 
      07-12-2005
Roedy Green <(E-Mail Removed)> wrote or quoted:

> The main thing that annoys me with them is, because the enum constants
> are implemented as anonymous inner classes, they cannot contain static
> variables or methods private to them. Further their constructors
> cannot access any statics.


Yet another reason to minimise the use of static variables in Java.
--
__________
|im |yler http://timtyler.org/ http://www.velocityreviews.com/forums/(E-Mail Removed) Remove lock to reply.
 
Reply With Quote
 
 
 
 
Thomas G. Marshall
Guest
Posts: n/a
 
      07-13-2005
Tim Tyler coughed up:
> Roedy Green <(E-Mail Removed)> wrote or quoted:
>
>> The main thing that annoys me with them is, because the enum
>> constants are implemented as anonymous inner classes, they cannot
>> contain static variables or methods private to them. Further their
>> constructors cannot access any statics.

>
> Yet another reason to minimise the use of static variables in Java.
>> im |yler http://timtyler.org/ (E-Mail Removed) Remove lock to
>> reply.


Except.........

In pre1.5, rolling your own type-safe enums was best accomplished with
statics.

http://groups-beta.google.com/group/...3c1c7f185dcabf





--
Puzzle: You are given a deck of cards all face down
except for 10 cards mixed in which are face up.
If you are in a pitch black room, how do you divide
the deck into two piles (may be uneven) that each
contain the same number of face-up cards?
Answer (rot13): Sebz naljurer va gur qrpx, qrny bhg
gra pneqf naq syvc gurz bire.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Enums without identifier, enums and typedef =?utf-8?b?QXNiasO4cm4gU8OmYsO4?= C Programming 10 01-20-2007 01:20 AM
Still Loving Python Kamilche Python 46 12-15-2005 12:35 AM
P&S loving idiots, beware... Rich DVD Video 41 11-03-2005 09:00 PM
PyCon Wiki: tender loving care needed Steve Holden Python 3 11-27-2003 01:16 AM
DVD Verdict reviews: LOVING WALTER, THE PACT OF SILENCE, and more! DVD Verdict DVD Video 0 11-26-2003 10:04 AM



Advertisments