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
  • PrintPrint

SLAP

SLAP insists that all your code within a method live at the same level of abstraction. In other words, you shouldn’t have a method in which part of it deals with low-level database connectivity, another part with high-level business code, and another with web service plumbing. Of course, such a method would also violate Beck’s composed method rule. But even if you have a cohesive method, you should make sure that all the lines of code share the same abstraction level.

Here’s an example. Consider this method, taken from a sample JEE e-commerce site (slightly more complex than the one in the previous examples). This particular method takes a shopping cart and adds an order (which in turn adds line items). For simplicity’s sake, it also uses low-level JDBC, but that’s peripheral to the SLAP discussion.


  

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


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint