Friday, March 23, 2012

SD Chapter 6: Developing the Domian Classes

The author's use chapter 6 of the SD book not only to define what domain classes are, but to also use the example of domain classes to teach a few key lessons about general code improvement.  Those lessons include getting to know a new code base, class design principles, and refactoring.

For getting familiar with a new code base, the chapter begins by going over how to read a design document.  This includes identifying classes, basically looking for 'nouns' (if the code is written effectively), finding the instance variables, and figuring out where the methods and functions are.  After getting this basic feel for the code, they then go into how to actually read the code.  For this, the book lays out three key goals:

   1.  To understand the overall architecture and functionality of the existing software.

   2.  To learn the vocabulary established by the domain classes.

   3.  To identify the extent to which to which the code must be refactored before it can be modified
        to support the functions of the new system.

After a lengthy section on modifying the domain classes, there is this tiny section, section 6.3, which neatly sums up how to design an effective class:

   1.  Is there a need?  In other words, is this functionality already elsewhere in the code base. 

   2. Information hiding...private on those instance variables!

   3. Object integrity.  Basically initializing all instance variables with a constructor.

   4.  Cohesion.  The class should be responsible for only one job.

   5.  Coupling.  Kept to a minimum.

   6.  Accessors.  Or getters.

   7.  Mutators.  Or setters.

And lastly, the book goes over the importance of refactoring.  In this section it talks about removing useless functions in the code base.  Are the setters and getters ever even used?  Is the function either redundant or useless?  If so, get it out if there.  All together this chapter provided a good review of material that every developer should be familiar with and have tattooed on their forearm.

No comments:

Post a Comment