Always on getter and setters

Welcome to anti-refactoring lesson 2.

There are painters that paint with pencils or brushes and painter that paints with a bucket. A bucket is very effective if you just want a canvas filled. An example:

1    private String prefix;
2    public String getPrefix(){
3        return getClass().getPackage().getName();
4    }
5    public void setPrefix(String prefix) {
6        this.prefix = prefix;
7    }

Neat! I don't even think that an IDE can produce dumb stuff like this: set a value, and ignore it. Remembering the principle of the minimum surprise...

Fortunately Eclipse warned me that prefix is never used; in a complete mess like the one I am getting Eclipse is an invaluable ally. Slowly cleaning up...


No Responses to “Always on getter and setters”  

  1. No Comments

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>



Calendar

October 2008
M T W T F S S
« Sep   Nov »
 12345
6789101112
13141516171819
20212223242526
2728293031  

Follow me

twitter flickr LinkedIn feed

Subscribe by email

Enter your email address:

Archives


Categories

Tag Cloud


Listening