Sue's Burger Shop

Consider a fictional restaurant called Sue's Burger Shop. Let's assume for purposes of simplicity that the shop sells only burgers. Let's model this simply as a burger and start from there. Furthermore, I'm going to assume that you've been awake until this point and you understand that an interface for a base class is a great idea here. So let's model the basic burger in terms of a sandwich (operations such as purchase, eat, and so on are suppressed). See Figure 5.1.

Figure 5.1. The hamburger hierarchy

Now we decide that we want to sell Cheeseburgers as well (see Figure 5.2). Hmm, inheritance to the rescue…

Figure 5.2. Extending ...

Get Joy of Patterns: Using Patterns for Enterprise Development, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.