Home > Articles > Software Development & Management > Object Technology

  • Print
  • + Share This
This chapter is from the book

Objects Doing

Peanut Butter, Again

Consider the peanut-butter-and-jelly sandwich example again. For simplicity, assume that the process has two types of bread (thick or thin) and three kinds of ingredients: one jelly (grape) and two peanut butters (plain or chunky). Also, a sandwich is assembled from two bread slices and a given amount (light or heavy) of one ingredient is spread on each bread slice. The object model should not care whether the slices were added to the sandwich first, and then ingredients applied to them, or vice versa. However, regardless of the order, something in the object model should enforce the following business rules from our sandwich domain experts: (1) a sandwich requires two slices of the same type of bread; (2) a thin bread slice cannot support chunky peanut butter; (3) a thin bread slice cannot support a heavy application of an ingredient; and (4) one bread slice must contain peanut butter and the other must contain jelly.

The peanut-butter-and-jelly sandwich object model is shown in Figure 1. A peanut-butter-and-jelly sandwich is an assembly of two bread slices with ingredients applied on them according to the business rules. A transaction object, application, records how much of an ingredient was applied to each bread slice. Notice that a bread slice is both a part in an assembly and a place for a transaction. Part conflict collaboration rules keep a bread slice with an ingredient on it from being added to a sandwich that already has a bread slice with the same ingredient. Place conflict collaboration rules prevent a bare bread slice from receiving an inappropriate ingredient.

Figure 1. The peanut-butter-and-jelly sandwich object model.

Now consider the peanut-butter-and-jelly sandwich business process. Creating the application transaction is the crucial step in the business process of building a peanut-butter-and-jelly sandwich because this step verifies the business rules as it tries to link the application object to its ingredient and bread slice collaborators. So, which object makes the application transaction? Is it (a) the sandwich, (b) the slice, (c) the ingredient, or (d) the ingredient manager-controller?

Clearly, the choice is between the bread slice and the ingredient; they are the collaborators of the application, and they have the relevant information and business rules. Use first-person object think to pick between the two. For the bread slice, object think says, "I am a bread slice. I have an ingredient applied on me in either a light or heavy amount." For the ingredient, object think says, "I am an ingredient. I apply myself to a bread slice in either a light or heavy amount." Notice that the action of applying ingredient is third-person for a bread slice and first-person for an ingredient. Obviously, the correct answer is (c); an ingredient creates the application object when it applies itself on a bread slice.

  • + Share This
  • 🔖 Save To Your Account