Re: Ambiguous Refactoring Solution
Adam Sroka <[email protected]>
| Newsgroups | gmane.comp.programming.refactoring |
|---|---|
| Message-ID | <[email protected]> |
On Mon, Sep 21, 2009 at 11:08 PM, bryanedds <[email protected]> wrote: > > > > My issue is that I have a class that is 613 lines of C++ code. This is a very fat class, but it's moderately cohesive. I would like to refactor it to address the size issue. The problem is that I don't have a specific enough problem that the refactoring will solve. This seems to ambiguate the refactoring solution. For example, I could do an extract subclass. That would be a simple solution. Or, I could extract a strategy class that the original class delegates to. This is more complex, but will probably be more future proof. Or, I could extract a mediator class. There are many choices. > Start here: http://www.industriallogic.com/papers/smellstorefactorings.pdf I honestly can't imagine a 613 line class file that doesn't have some obvious smells - even in C++ ;-) Though, I suppose anything is possible. Find a smell that matches what you are seeing and apply one of the suggested refactorings from the list. > Now, usually I have an immediately pressing context from which to derive a refactoring solution. That context is usually of reuse. I can ask myself, "how do I refactor this class in order to best facilitate reuse of its key elements?" The refactoring solution often very neatly falls out of the reuse context. Such a context is absent here. > You don't need a context like reuse to understand how to refactor a class. Try to see how the class could be made simpler. Look for duplication. Look for complex conditionals. Look for any of the things in the list I referenced. > I could sit and theorize about what I would do in a future reuse context. But that seems to be irresponsibly speculative. > I agree. If you approach the problem that way you are almost certainly looking for a solution that violates YAGNI. > Any one have any ideas on how to refactor when the usual driving forces are absent? > If by the "usual driving forces" you mean that the class is complex, difficult to understand, and contains duplication, I'd bet that a 613 line class has plenty. If, on the other hand, you have no reason to be looking at this class in the first place. i.e. it isn't related to any story that you are working on, then I agree with the other posters who suggest that you should wait until there is a reason. It's not clear to me that that is the case here. If you have a reason to be looking at the class, and it sucks, you should fix it. ------------------------------------ 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: mailto:[email protected] mailto:[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/