Responsibilities of a Recipe

Consider the representation of an individual recipe. Programmers with experience in older software development techniques might think that a recipe is nothing more than a holder for data values. A recipe, clearly, just contain a list of ingredients, and a list of steps to be performed in the transformation of those ingredients into the final product.

In the object oriented world, one should never think of data as simply being a passive collection of items. Instead, one should imagine everything as an active entity, able to perform actions as well as hold data values.

So, what activities should a recipe perform? Well, perhaps it makes sense to place the editing responsibility on the recipe itself. That is, a recipe not only knows how to display itself on some output device, but also knows how to interpret the user activities that permit editing or annotating the receipt data values.

A recipe knows how to display itself, both on the interactive console and perhaps on an attached printer.

Later on, we will add new behaviors to a recipe. For example, a recipe will know how to scale itself, taking a recipe written for five people and producing a new recipe for 47. It will know how to add its list of ingredients to a grocery list, and so on.

[audio] 17 [real] 17 Text to accompany slide 17, in Chapter 2 of An Introduction to Object-Oriented Programming