O'Reilly logo

Joy of Patterns: Using Patterns for Enterprise Development, The by Brandon Goldfedder

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required