dcsimg
April 2, 2020
Hot Topics:

Five Ways to Reduce the Size of Classes

  • 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.


This article was originally published on June 16, 2011

Enterprise Development Update

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


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