14 Mar 2010 21:15
Chatting about Extract Class
K. Cassell <kcassell2001 <at> yahoo.com>
2010-03-14 20:15:36 GMT
2010-03-14 20:15:36 GMT
I'm curious about how other people view the Extract Class refactoring. For instance, do you use it much, how do you go about it, what would help you do it more often? In my case, I extract methods all the time, but extract classes much less often. There are a couple of reasons. First, there isn't as much opportunity to extract classes - there are a lot more classes than methods. But secondly, it's hard. It's not easy to decide what belongs in the new classes, and the tool support isn't as good. Usually for my code, I decide to extract a class when it gets above a certain size, and I feel embarrassed that I let it get so big. I typically have a fair idea of where I should split it. For other people's code, it's worse. It usually isn't obvious to me where it should be split. Generally, I would look for semantic clues for common function, e.g. look for method identifiers that have common parts. For example, if there were a lot of methods with "XML" in the name, I might look into making some kind of XML helper class. For actually performing the refactoring, I much prefer to use tools. Of the ones I know about for Java, I like IntelliJ's IDEA the best, even though I am an Eclipse user. Eclipse 3.5.1 basically just let me pull out fields into a new class; IntelliJ let me pull out both fields and methods. Unfortunately, IntelliJ's implementation was buggy. My extracted classes often had compile errors. However, these were generally easy to fix, and I felt that IntelliJ was doing a lot more for me than it was doing to me. ;) Without tools, I seldom try to extract classes from other people's code. Generally, it seems to be too much work for too little result. Some might call me lazy. I prefer "analytical". :) I'm interested in hearing your opinions/war stories. Regards, Keith Cassell ------------------------------------(Continue reading)
RSS Feed