April 20, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Five Ways to Reduce the Size of Classes

  • June 16, 2011
  • By Developer.com Staff

Andrew Binstock writes that the best developers keep their classes to 50-60 lines of code. How can you do that? Here are five techniques:

  1. Diminish the workload -- Each class should just one thing.
  2. Avoid primitive obsession -- Don't use collections in their raw form.
  3. Reduce the number of class and instance variables -- If you have a lot of variables, you can probably move a group of them to a separate class.
  4. Subclass special-case logic -- If you have logic that isn't used very often, move it to a sub-class or a separate class.
  5. Don't repeat yourself (DRY) -- Discipline yourself to avoid duplicate code in both the writing and the maintenance phases.

View article


Tags: programming




Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel