The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
April 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Various questions about the JFC

Posted by Nigel Sandever on May 24, 2001 at 8:46 AM

Hi,

Im a long time (20+ yrs) professional prog., but a neophite at java and there are various things regarding the JFC that strick me as suboptimal:)

Maybe there are some opinions out there that will clarify things for me.

1) Why do we have a xxxx = getXxxx(), and a setXxxx( xxxx ) calls...
not xxxx = xxxx() and xxxx( xxxx );

eg. to clarify

class DecimalFormat {
...
void setMultiplier( int newValue ) {...}
int getMultiplier() {...}
}

Why not

class DecimalFormat {
...
int multiplier( int newValue ) {...} // (1)
int multiplier() {...}
}

Note: That the "set" method also returns the value set. This has the effect of allow one to "chain" method calls.
----------------------------------------------------------------

2) Why dont methods that modify the state of an object also return the modified object (reference)???

So that instead of coding...

void paint( Graphics g ) {
Graphics2D g2 = (Graphics2D)g;
AffineTransform tx = g2.getTransform().translate( w/2, h/2 );
g2.setTransform( tx );
...
)

you could code:

void paint( Graphics g ) {
Graphics2D g2 = (Graphics2D)g;
g2.setTransform( g2.getTransform().translate( w/2, h/2 ) );
...
)

Which (to me) clarifies the code and "saves" and intermediate variable.

Is there some OO reason for not doing this....I notice that it does happen some places like

Color color2 = color.darker();

though in this instance I'd prefer it if the darker() method returned a darker version of the color WITHOUT modifying the original... Or change the method name to darken() to indicate that it is modifying THIS color not just returning a darker one.

I end up coding stuff like:

...
Color sunlite = somecolor;
Color shade = new Color( sunlite.getRGB() ).darker();
...

When I want to derive another shade of a color and retain the original.

3) Why do they (SUN?) not use more method overiding?

eg.

Class Graphics {
void drawRect( ...); NOT draw( Rectangle );
void drawImage( Image i ....); NOT draw( Image i ... );
void drawString( String s ... ); NOT draw( String s ... );
etc.
}

Sorry for the rambling, Nigel Sandever.

PS. If this system doesn't automatically forward replies to my email, I'd appreciate it if any responders did.... it much easier (for me:) if I dont have to keep coming back and checking...





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us