dcsimg
September 19, 2018
Hot Topics:

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



Originally published on https://www.developer.com.


Comment and Contribute

 


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

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.

Sitemap

Thanks for your registration, follow us on our social networks to keep up-to-date