Monday, March 14, 2011

Class organization

I am putting together a theory of  class code readability organization with the assertions that


  • Classes consistently organized are easier to read and understand
  • Fields should be private
  • Consistent internal state is preferable to passing around invalid objects that can communicate they are invalid (immutability vs IDataErrorInfo)
This layout is my hypothesis of what a good consistent layout would be:

  1. private fields
  2. constructor(s)
  3. Initializers and wiring
    1. for example event wiring
  4. non-public properties
  5. public operations
  6. public properties
  7. explicit event plumbing
    1. For example designer auto-generated event handlers
  8. Other plumbing or utilities
As with any theory or concept, the main ways to learn from it are 

  • to communicate it out for feedback 
    • other people's viewpoints can help you find your blind spots
    • you can become aware of situations where the idea or solution doesn't fit and why
  • apply it
  • look at it with a critical eye for places or reasons that it works well and places it doesn't
    • keep an open mind that one size does not fit all
  • solicit feedback for applications of the idea
    • other people can better see past your blind spots
    • explaining it helps keep or find perspective
    • any critical thinking or discussion is likely to be beneficial to all involved parties

No comments:

Post a Comment