The Essence of Object-Oriented Programming for Android Apps - dummies

The Essence of Object-Oriented Programming for Android Apps

By Barry Burd

For this example of using object-oriented programming in Java, imagine Andy’s Cheese and Java Emporium carries fine cheeses and freshly brewed java from around the world (especially from Java in Indonesia). The Emporium is in Cheesetown, Pennsylvania, a neighborhood along the Edenville–Cheesetown Road in Franklin County.

The emporium sells cheese by the bag, each containing a certain variety, such as Cheddar, Swiss, Munster, or Limburger. Bags are labeled by weight and by the number of days the cheese was aged (admittedly, an approximation). Bags also carry the label Domestic or Imported, depending on the cheese’s country of origin.

Before starting up the emporium, Andy had lots of possessions — material and otherwise. He had a family, a cat, a house, an abandoned restaurant property, a bunch of restaurant equipment, a checkered past, and a mountain of debt. But for the purpose of this narrative, Andy had only one thing: a form. Yes, Andy had developed a form for keeping track of his emporium’s inventory. The form is shown here.

image0.jpg

Exactly one week before the emporium’s grand opening, Andy’s supplier delivered one bag of cheese. Andy entered the bag’s information into the inventory form. The result is shown.

image1.jpg

Andy had only a form and a bag of cheese (which isn’t much to show for all his hard work), but the next day the supplier delivered five more bags of cheese. Andy’s second entry looked like the one shown in this figure, and the next several entries looked similar.

image2.jpg

At the end of the week, Andy was giddy: He had exactly one inventory form and six bags of cheese.

The story doesn’t end here. As the grand opening approached, Andy’s supplier brought many more bags so that, eventually, Andy had his inventory form and several hundred bags of cheese. The business even became an icon on Interstate Highway 81 in Cheesetown, Pennsylvania. But as far as you’re concerned, the business had, has, and always will have only one form and any number of cheese bags.

That’s the essence of object-oriented programming!