How To Peel An Object-Oriented Orange
Posted by Allan in Prose on March 28, 2011 6:38 pm
First you instantiate a Person class which in turn extends a Primate class which implements, among other methods, MoveThumb(). Assuming that this instance of Person we’ll call bob successfully tries procuring a fruit object of type Orange by passing an Intent to another Person class whose Occupation property is defined as “fruit vendor” along with the necessary funds (and since bob used a debit card, required interaction with an instance of a Bank object which returned an Authorization object to the fruit vendor’s Cash Register Object which for the purposes of this explanation was dynamically created as the need for it arose) — anyway, assume we have procured a fruit object of type Orange…
Implementing the Peel method: To peel this fruit object of type Orange we’ll call orange, we need to first try grasping orange. Here we need to make sure we handle a few exceptions like LIMBS_MISSING or INSUFFICIENT_GRIP which could put an unceremonious halt to this exercise. We then check bob.thumbnail.length and compare it to orange.peel.thickness to see if he has sufficient nail length in order to pierce said orange. To be thorough, we should test for this case and appropriately handle with a knife object, but that’s beyond the scope of this simple tutorial. If we determine that bob.thumbnail.length is sufficient, we create a while loop: while (orange.peelExists) { bob.digNail(orange); bob.detachPeel(orange) }
Once you have successfully implemented the Peel method, you could try it with other fruit object types! As an additional exercise, try the same method on the following fruit types: Grapefruit, Lemon, Blood Orange, Pineapple, and Coconut!