Decoupling the reference train
Now let’s take knowledge of these three connection types and see how we can associate every class in the example UML class diagram that follows, using a few rules. Once everything is associated, we’ll implement decoupling in an example and look at the benefits this brings.
Modularity and decoupling
We’ll start with a bunch of scattered classes, which are organized in a way that will function but is messy to work with, as shown in Figure 7.5. To make everything function here clearly, the developer has added references, as and when needed, to any class.
Figure 7.5 – Example UML showing a messy system
Let’s analyze how the Character to Projectile interaction occurs by looking at the sequence diagram in Figure 7.6. When the character fires, it spawns a projectile but then doesn’t hold onto the reference. Instead, the projectile grabs a reference to the character and when it hits...