Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #12535
| From | Daniel Pitts <newsgroup.nospam@virtualinfinity.net> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Swing is dead! Long live Swing. |
| References | (5 earlier) <6f72r.16359$L12.15612@newsfe23.iad> <MPG.29b489064e43ada39896f5@202.177.16.121> <jidthv$psp$1@dont-email.me> <MPG.29b7714321f8377c9896f6@202.177.16.121> <jikluo$ed5$1@news.albasani.net> |
| Message-ID | <L_s3r.2731$HX7.2640@newsfe11.iad> (permalink) |
| Date | 2012-02-29 09:10 -0800 |
On 2/29/12 12:00 AM, Lew wrote:
> Wanja Gayk wrote:
>> markspace wrote:
>>> ... For situations where I might be tempted to just use strings,
>>> I try to substitute enums. For example, instead of
>>>
>>> bind( someComponent, "event-name" );
>>>
>>> I'd use this:
>>>
>>> bind( someComponent, Events.NAME );
>>>
>>> It provides automatic syntax checking, and is much easier to refactor if
>>> names need to be changed or moved around later.
>>>
>>> Any thoughts on this idea?
>>
>> I think the same way.
>> I'm even going further and strongly propose preferring Enums to boolean
>> parameters and this is why:
>> http://brixomatic.wordpress.com/2010/02/24/boolean-harmful/
>
> +1
>
> This might irritate those who already find Java verbose, since 'String's
> are more compact to declare, but type safety and refactorability [sic]
> is a payoff in many situations.
>
> I'm even worse, because I pump a "friendly" string representation into
> the enum.
> <http://docs.oracle.com/javase/7/docs/api/java/lang/Enum.html#toString()>
> «An enum type should override this method when a more
> "programmer-friendly" string form exists.»
I'm even worse than that. My designs often include replacing a boolean
with an Enum that has *logic* in it. Flyweight strategy pattern.
public enum FooStrategy {
ONE_WAY {
public void handle(Foo foo) {
foo.doItOneWay();
}
},
ANOTHER {
public void handle(Foo foo) {
foo.doItAnother();
}
}
;
public abstract void handle(Foo foo);
}
This is more verbose but ends up being more flexible and easier to
maintain. Enums can even implement interfaces, so you could add
additional layer of abstraction which allows custom or statefull
implementations alongside the the enum implementations.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
Swing is dead! Long live Swing. Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2012-02-15 19:25 -0800
Re: Swing is dead! Long live Swing. Roedy Green <see_website@mindprod.com.invalid> - 2012-02-15 20:13 -0800
Re: Swing is dead! Long live Swing. Arne Vajhøj <arne@vajhoej.dk> - 2012-02-16 18:33 -0500
Re: Swing is dead! Long live Swing. Novice <novice@example..com> - 2012-02-16 19:13 +0000
Re: Swing is dead! Long live Swing. Arne Vajhøj <arne@vajhoej.dk> - 2012-02-16 18:32 -0500
Re: Swing is dead! Long live Swing. Novice <novice@example..com> - 2012-02-17 16:35 +0000
Re: Swing is dead! Long live Swing. Arne Vajhøj <arne@vajhoej.dk> - 2012-02-17 18:00 -0500
Re: Swing is dead! Long live Swing. Arne Vajhøj <arne@vajhoej.dk> - 2012-02-27 21:05 -0500
Re: Swing is dead! Long live Swing. Arne Vajhøj <arne@vajhoej.dk> - 2012-02-16 18:29 -0500
Re: Swing is dead! Long live Swing. Knute Johnson <nospam@knutejohnson.com> - 2012-02-16 15:50 -0800
Re: Swing is dead! Long live Swing. Arne Vajhøj <arne@vajhoej.dk> - 2012-02-16 18:52 -0500
Re: Swing is dead! Long live Swing. Knute Johnson <nospam@knutejohnson.com> - 2012-02-16 16:01 -0800
Re: Swing is dead! Long live Swing. Arne Vajhøj <arne@vajhoej.dk> - 2012-02-16 19:07 -0500
Re: Swing is dead! Long live Swing. Wanja Gayk <brixomatic@yahoo.com> - 2012-02-20 20:27 +0100
Re: Swing is dead! Long live Swing. Arne Vajhøj <arne@vajhoej.dk> - 2012-02-20 18:39 -0500
Re: Swing is dead! Long live Swing. Wanja Gayk <brixomatic@yahoo.com> - 2012-02-21 02:09 +0100
Re: Swing is dead! Long live Swing. Arne Vajhøj <arne@vajhoej.dk> - 2012-02-20 20:28 -0500
Re: Swing is dead! Long live Swing. Arne Vajhøj <arne@vajhoej.dk> - 2012-02-20 20:29 -0500
Re: Swing is dead! Long live Swing. Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-02-25 11:37 -0400
Re: Swing is dead! Long live Swing. Arne Vajhøj <arne@vajhoej.dk> - 2012-02-25 10:58 -0500
Re: Swing is dead! Long live Swing. Wanja Gayk <brixomatic@yahoo.com> - 2012-02-26 18:24 +0100
Re: Swing is dead! Long live Swing. markspace <-@.> - 2012-02-26 10:27 -0800
Re: Swing is dead! Long live Swing. Lew <noone@lewscanon.com> - 2012-02-26 13:16 -0800
Re: Swing is dead! Long live Swing. Arne Vajhøj <arne@vajhoej.dk> - 2012-02-26 18:05 -0500
Re: Swing is dead! Long live Swing. Wanja Gayk <brixomatic@yahoo.com> - 2012-02-28 23:19 +0100
Re: Swing is dead! Long live Swing. Lew <noone@lewscanon.com> - 2012-02-29 00:00 -0800
Re: Swing is dead! Long live Swing. Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-02-29 09:10 -0800
Re: Swing is dead! Long live Swing. Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-02-29 05:53 -0400
Re: Swing is dead! Long live Swing. Wanja Gayk <brixomatic@yahoo.com> - 2012-02-29 11:11 +0100
Re: Swing is dead! Long live Swing. Lew <noone@lewscanon.com> - 2012-02-26 13:16 -0800
Re: Swing is dead! Long live Swing. Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-02-26 19:32 -0400
Re: Swing is dead! Long live Swing. Lew <noone@lewscanon.com> - 2012-02-26 16:59 -0800
Re: Swing is dead! Long live Swing. Arne Vajhøj <arne@vajhoej.dk> - 2012-02-26 21:03 -0500
Re: Swing is dead! Long live Swing. Lew <noone@lewscanon.com> - 2012-02-26 21:22 -0800
Re: Swing is dead! Long live Swing. Arne Vajhøj <arne@vajhoej.dk> - 2012-02-27 21:00 -0500
Re: Swing is dead! Long live Swing. Wanja Gayk <brixomatic@yahoo.com> - 2012-02-28 23:34 +0100
Re: Swing is dead! Long live Swing. markspace <-@.> - 2012-02-16 16:43 -0800
Re: Swing is dead! Long live Swing. Roedy Green <see_website@mindprod.com.invalid> - 2012-02-17 09:24 -0800
Re: Swing is dead! Long live Swing. Arne Vajhøj <arne@vajhoej.dk> - 2012-02-17 17:52 -0500
csiph-web