Loving Enums

R

Roedy Green

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/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
T

Tim Tyler

Roedy Green said:
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.
 
T

Thomas G. Marshall

Tim Tyler coughed up:
Yet another reason to minimise the use of static variables in Java.

Except.........

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

http://groups-beta.google.com/group/comp.lang.java.programmer/msg/543c1c7f185dcabf





--
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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top