First of All… I want to know… Are you know What is re-factoring… Although I am not so much experienced as you are… But I am fan of “Agile Methodology and Extreme programming”. They provide a good approach to software development. In XP we have test before actual
development. But these code is not testable at Unit Testing levels.
Refactoring definition that I taken from a book on refactoring by Martin Fowler
Refactoring: a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behaviour.
I find this code need more concentration to understand. It also seems unmanageable to modify. There are too redundancy in the code.
About comments my views as following: I not say that there is not any Javadoc comment. Javadoc comments is necessary things to create a nice documented API
Martin Fowler said as about comments:
Don’t worry, we aren’t saying that people shouldn’t write comments. In our olfactory analogy, comments aren’t a bad smell; indeed they are a sweet smell. The reason we mention comments here is that comments often are used as a deodorant. It’s surprising how often you look at thickly commented code and notice that the comments are there because the code is bad.
Comments lead us to bad code that has all the rotten whiffs. Our first action is to remove the bad smells by refactoring. When we’re finished, we often find that the comments are superfluous.
If you need a comment to explain what a block of code does, try Extract Method. If the method is already extracted but you still need a comment to explain what it does, use Rename Method. If you need to state some rules about the required state of the system.
Tip: When you feel the need to write a comment, first try to refactor the code so that any comment becomes superfluous.
A good time to use a comment is when you don’t know what to do. In addition to describing what is going on, comments can indicate areas in which you aren’t sure.
A comment is a good place to say why you did something. This kind of information helps future modifiers, especially forgetful ones."
I am not so much expert in refactoring as I am learning these methodology, But I try to give some example by
modifying the DefaultAuthprovider after applying refactoring. I attached source here so that you can see the difference. That databased part most of classes is redundant. We can make it more manageable as other people also talked about database.
modified DefaultAuthProvider.java (7563 Bytes)
orginal DefaultAuthProvider.java (8477 Bytes)