9 Interception

 

In this chapter

  • Intercepting calls between two collaborating objects
  • Understanding the Decorator design pattern
  • Applying Cross-Cutting Concerns using Decorators

One of the most interesting things about cooking is the way you can combine many ingredients, some of them not particularly savory in themselves, into a whole that’s greater than the sum of its parts. Often, you start with a simple ingredient that provides the basis for the meal, and then modify and embellish it until the end result is a delicious dish.

Consider a veal cutlet. If you were desperate, you could eat it raw, but in most cases you’d prefer to fry it. But if you slap it on a hot pan, the result will be less than stellar. Apart from the burned flavor, it won’t taste like much. Fortunately, there are lots of steps you can take to enhance the experience:

  • Frying the cutlet in butter prevents burning the meat, but the taste is likely to remain bland.
  • Adding salt enhances the taste of the meat.
  • Adding other spices, such as pepper, makes the taste more complex.
  • Breading it with a mixture that includes salt and spices not only adds to the taste, but also envelops the original ingredient in a new texture. At this point, you’re getting close to having a cotoletta.1
  • Slitting open a pocket in the cutlet and adding ham, cheese, and garlic into the pocket before breading it takes us over the top. Now you have veal cordon bleu a most excellent dish.

9.1 Introducing Interception

9.1.1 Decorator design pattern

9.1.2 Example: Implementing auditing using a Decorator

9.2 Implementing Cross-Cutting Concerns

9.2.1 Intercepting with a Circuit Breaker

9.2.2 Reporting exceptions using the Decorator pattern

9.2.3 Preventing unauthorized access to sensitive functionality using a Decorator

Summary