Java Adapter Pattern Wiki Redux

J

John B. Matthews

Recently, the Java example in the Wikipedia article entitled "Adapter
Pattern" [1] was modified to use the keyword "final" in a way that may
be considered superfluous [2]. The revision also incorrectly used the
for-each loop. The example is reasonable, but it differs considerably
from one recently proposed [3]. I've edited the article, but I'd be
grateful for any review or corrections.

[1]<http://en.wikipedia.org/wiki/Adapter_pattern>
[2]<http://stackoverflow.com/questions/500517>
[3]<http://groups.google.com/group/comp.lang.java.programmer/browse_frm/thread/898c30260012fba3>
 
A

Alan Malloy

John said:
Recently, the Java example in the Wikipedia article entitled "Adapter
Pattern" [1] was modified to use the keyword "final" in a way that may
be considered superfluous [2]. The revision also incorrectly used the
for-each loop. The example is reasonable, but it differs considerably
from one recently proposed [3]. I've edited the article, but I'd be
grateful for any review or corrections.

[1]<http://en.wikipedia.org/wiki/Adapter_pattern>
[2]<http://stackoverflow.com/questions/500517>
[3]<http://groups.google.com/group/comp.lang.java.programmer/browse_frm/thread/898c30260012fba3>

Yes, those final keywords were ridiculous. It's kinda tacky for you to
do all these whitespace changes, though - it causes Wikipedia to report
a much larger diff than necessary. It doesn't look like the previous
whitespace was so awful, so I assume you didn't do this on purpose, but
rather your editor did it automatically and you didn't undo it.
Similarly, you seem to have moved a bunch of brackets around. I don't
recall if there's a "standard" indentation style for Java, but either
way people feel strongly about it, and if you start editing brace
placements in an article you just start a tug-of-war between two groups.
The article's also no longer internally consistent re: bracing. The
first half puts open-braces on the same line as the class/method, and
the second half puts them on a new line.

I do think, though, that the final modifiers on the member variables
wasn't superfluous. It's unnecessary in this example, but it
self-documents that the class author wants the object to be immutable.

I don't see what you mean by using the for-each loop wrong? They put a
silly "final" in there, but it doesn't look like you made any other changes.

For what it's worth, I think your horse/animal example is miles better
than this convoluted and useless line/rectangle nonsense.
 
M

markspace

John said:
Recently, the Java example in the Wikipedia article entitled "Adapter
Pattern" [1] was modified to use the keyword "final" in a way that may
be considered superfluous [2]. The revision also incorrectly used the
for-each loop. The example is reasonable, but it differs considerably
from one recently proposed [3]. I've edited the article, but I'd be
grateful for any review or corrections.

[1]<http://en.wikipedia.org/wiki/Adapter_pattern>
[2]<http://stackoverflow.com/questions/500517>
[3]<http://groups.google.com/group/comp.lang.java.programmer/browse_frm/thread/898c30260012fba3>


Well I have a few biases here, but it seems I've been blocked from
editing Wikipedia. Apparently someone from the west coast has been
posting harassing comments, and there's a block of a net-block for my
entire ISP. Oh well.

I do mostly agree with Alan's comments though.
 
J

John B. Matthews

Alan Malloy said:
John said:
Recently, the Java example in the Wikipedia article entitled
"Adapter Pattern" [1] was modified to use the keyword "final" in a
way that may be considered superfluous [2]. The revision also
incorrectly used the for-each loop. The example is reasonable, but
it differs considerably from one recently proposed [3]. I've edited
the article, but I'd be grateful for any review or corrections.

[1]<http://en.wikipedia.org/wiki/Adapter_pattern>
[2]<http://stackoverflow.com/questions/500517>
[3]<http://groups.google.com/group/comp.lang.java.programmer/ browse_frm/thread/898c30260012fba3>

Yes, those final keywords were ridiculous. It's kinda tacky for you
to do all these whitespace changes, though - it causes Wikipedia to
report a much larger diff than necessary. It doesn't look like the
previous whitespace was so awful, so I assume you didn't do this on
purpose, but rather your editor did it automatically and you didn't
undo it. Similarly, you seem to have moved a bunch of brackets
around. I don't recall if there's a "standard" indentation style for
Java, but either way people feel strongly about it, and if you start
editing brace placements in an article you just start a tug-of-war
between two groups. The article's also no longer internally
consistent re: bracing. The first half puts open-braces on the same
line as the class/method, and the second half puts them on a new
line.

Alan Malloy & markspace: Thanks both for commenting. I see what you
mean about the whitespace. I used the "undo" button to restore the
original; if you select both revisions you'll see the two line change
that I alone made.

Re braces: Indeed, the original "//Before" section uses one style and
"//After" uses another. I left that alone. I use either style, as the
occasion demands; but I am unable to resist sharing my favorite brace
joke:

I do think, though, that the final modifiers on the member variables
wasn't superfluous. It's unnecessary in this example, but it
self-documents that the class author wants the object to be
immutable.

I don't see what you mean by using the for-each loop wrong? They put
a silly "final" in there, but it doesn't look like you made any other
changes.

IIUC, the interlocutor changed a "for int i" to "for Shape s", but
neglected to update the reference inside the loop, accordingly.
For what it's worth, I think your horse/animal example is miles
better than this convoluted and useless line/rectangle nonsense.

The credit goes to markspace.
 
A

Arne Vajhøj

Recently, the Java example in the Wikipedia article entitled "Adapter
Pattern" [1] was modified to use the keyword "final" in a way that may
be considered superfluous [2]. The revision also incorrectly used the
for-each loop. The example is reasonable, but it differs considerably
from one recently proposed [3]. I've edited the article, but I'd be
grateful for any review or corrections.

[1]<http://en.wikipedia.org/wiki/Adapter_pattern>
[2]<http://stackoverflow.com/questions/500517>
[3]<http://groups.google.com/group/comp.lang.java.programmer/browse_frm/thread/898c30260012fba3>

Looks fine to me.

I don't like the "one final keyword per line of code" practice.

I would have used the old instanceof and () cast instead
of those Class methods, but that does not seem to be
important for the point.

Arne
 
J

John B. Matthews

Arne Vajhøj said:
Recently, the Java example in the Wikipedia article entitled "Adapter
Pattern" [1] was modified to use the keyword "final" in a way that may
be considered superfluous [2]. The revision also incorrectly used the
for-each loop. The example is reasonable, but it differs considerably
from one recently proposed [3]. I've edited the article, but I'd be
grateful for any review or corrections.

[1]<http://en.wikipedia.org/wiki/Adapter_pattern>
[2]<http://stackoverflow.com/questions/500517>
[3]<http://groups.google.com/group/comp.lang.java.programmer/browse_frm/thread/898c30260012fba3>

Looks fine to me.

I don't like the "one final keyword per line of code" practice.

I would have used the old instanceof and () cast instead
of those Class methods, but that does not seem to be
important for the point.

Arne: Thanks for looking at this. Your point about the focus of example
code is well taken.
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top