RE: Chatting about Extract Class

"Hameed, Mudassir (Gale)" <[email protected]> Mon, 15 Mar 2010 10:31:34 -0400
Newsgroups gmane.comp.programming.refactoring
Message-ID <[email protected]>
I do extract into classes at times. But whether you extract into classes or methods, it's a good idea to get the code under unit test coverage before you refactor.

One way to decide whether you need a new class is to look at the name of the class. XMLHelper for example can "help" in so many ways. These types of classes should ideally be broken down further. XMLParser on the other hand has just one function, to parse. Similarly URLHelper vs. URLExtractor, DatabaseUtil vs. DatabaseConnector or DataRetriever.

Mudassir Hameed
Gale | Cengage Learning

________________________________
From: [email protected] [mailto:[email protected]] On Behalf Of K. Cassell
Sent: Sunday, March 14, 2010 4:16 PM
To: [email protected]
Subject: [refactoring] Chatting about Extract Class



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



[Non-text portions of this message have been removed]



------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/refactoring/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/refactoring/join
    (Yahoo! ID required)

<*> To change settings via email:
    [email protected] 
    [email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/