Java Reference
In-Depth Information
(how interdependent parts of the system are) and cohesion (how related the various parts of the
system are).
But for many programmers, the key day-to-day concern is debugging during maintenance: this
code crashed because it observed some unexpected value. Why is it this way and how did it get
this way? Just think of how many of your maintenance concerns fall into this category! [ 1 ] It turns
out that the ideas of no side effects and immutability , which functional programming promotes,
can help. Let's examine this in more detail.
1 We recommend reading Working Effectively with Legacy Code (Prentice Hall, 2004) by
Michael Feathers for further discussion on this topic.
13.1.1. Shared mutable data
Ultimately, the reason for the unexpected variable value problems just discussed is that shared
mutable data structures are read and updated by more than one of the methods your
maintenance centers on. Suppose several classes keep a reference to a list. Who owns this list?
What if one class modifies it? Do other classes expect this change? How do other classes learn of
this change? Do they need to be notified of this change to satisfy all assumptions on this list, or
should they make a defensive copy for themselves? In other words, shared mutable data
structures make it harder to track changes in different parts of your program. Figure 13.1
illustrates this idea.
Figure 13.1. A mutable shared across multiple classes. It's difficult to
understand who the owner is.
 
Search WWH ::




Custom Search