Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

7. Reference Implementation > 7.5. Second Refactoring

7.5. Second Refactoring

In the class diagram shown in Figure 7.1, the Bill class has a bidirectional relationship to the AuditFacade class. This design has two fundamental flaws. The Bill is tightly coupled to the concrete AuditFacade class, and the relationship is bidirectional. Bad all around! This can be seen in Listing 7.3, illustrating the Bill class’s audit method.

Listing 7.3. Audit Method of the Bill Class


public void audit() {
   AuditFacade auditor = new AuditFacade();
   this.billData.setAuditedAmount(auditor.audit(this));
   this.persist();
}


Notice that the audit method actually creates the AuditFacade, calls the audit method, and passes a reference to Bill. Ugly. Let’s clean this up a little bit. Although there are obvious technology reasons why we need to clean this up, there is also a motivating business force.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial