my dog learned polymorphism*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Refactoring: need help in finding bad smells Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Refactoring: need help in finding bad smells" Watch "Refactoring: need help in finding bad smells" New topic
Author

Refactoring: need help in finding bad smells

Goran Silic
Greenhorn

Joined: May 11, 2012
Posts: 3
I need help finding bed smells in 3 java classes. I'm at a beginner level of refactoring and I've really have problem spotting bed smells. If someone could point them out to me I'll be most appreciated. Thanks...
Because the JavaRanch won't let me for some reason to attach files in .zip, .rar, .txt, .java, .docx etc I have to put my code here:

Here's the code for Background.java:



Here's the code for Cad.java:





Here's the code for Table.java:

Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1007
    
    3
What smells the worst to you?
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2343
    
  28

Can you provide a high level overview of the design. It will make it easier to understand what a class does if we know what the class is suppossed to be

Actually, I would say a bad smell #1:- Missing class level doc. Ideally you should be able to describe what the class represents in couple of lines, and that description should go in class level javadoc. At the very best, lack of javadocs indicates laziness on the part of the developer, and at the worst, it could mean that the developer doesn't think of classes as representation of real entities.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4458
    
    6

Some ways you can start developing a sensitivity to code smells:
  • Try writing a unit test for your code
  • Try adding some functionality
  • Try modifying the current functionality
  • Try explaining what the code does

  • If you find it hard to do one or more of these things, there's probably something that needs to be refactored. I'm kind iffy on the "No documentation is a smell" thing suggested by Jayesh because I believe that code should be self-documenting. OTOH, there are some cases where I do find that some high-level comments can be very helpful indeed in giving the reader an understanding of the intent of the code and the thought process of the authors when they wrote the code and made the design decisions that they made.


    Junilu - [How to Ask Questions] [How to Answer Questions]
     
     
    subject: Refactoring: need help in finding bad smells