Fairytales & Object Design

Due Sunday June 1st, 8pm
Late submissions accepted for -10 pts until June 2nd, 8pm

In this assignment, you don't have to do any real programming. What we would like is for you to take some time and think about the things you have learned in Object Oriented Programming. Inheritance, polymorphism, members, methods, and all the rest of OOP are important things to understand. This understanding comes, like so many things in Computer Science, through experience. To that end, we are assigning you an exercise in Object Hierarchy Design. You will take a classic fairy tale (Little Red Riding Hood, to be exact) and write up the object interfaces (.h files) that you would use if you were creating a set of objects to implement the story in C++.

An Example

One fine day during harvest time, Tom Fitzpatrick was taking a ramble through the countryside, and went along the sunny side of a hedge. All of a sudden he heard a clacking sort of noise a little before him in the hedge.

"Dear me," said Tom, "but isn't it surprising to hear the birds chattering so late in the season?" So Tom stole on, going on the tips of his toes to see if he could get a sight of what was making the noise and see if he was right in his guess. The noise stopped, but as Tom looked sharply through the bushes, what should he see in a nook of the hedge but a brown pitcher, that might hold about a gallon and a half of fine dark beer. By-and-by a little wee teeny tiny bit of an old man, with a little crooked hat stuck upon the top of his head and a leather apron hanging before him pulled out a little wooden stool and stood up upon it, and dipped a little mug into the pitcher and took out the full of it, and put it beside the stool and then sat down under the pitcher and began to work at drinking the fine stuff.

"Well, by the powers," thought Tom to himself, "I often heard tell of Leprechauns, and, to tell the truth I never rightly believed in them, but here's one of them in real earnest. If I do things rightly, I'm set for life. They say a body must never take their eyes off them, or they'll escape."

Tom now stole on a little further, with his eye fixed on the little man just a cat does with a mouse. So when he got up quite close to him, "Bless your work, neighbor," said Tom.

The little man raised up his head, and "Thank you kindly," said he.

"I wonder you'd be working on this holiday!" said Tom.

"That's my business, not yours," was the reply.

"Well, maybe you'd be civil enough to tell me what you've got in the pitcher there?" said Tom.

"That I will, with pleasure," said he, "it's good beer."

"Beer!" said Tom. "Thunder and fire! Where did you get it?"

"Where did I get it, is it? Why, I made it. And what do you think I made it of?"

"I imagine you made it of malt, what else?" said Tom.

"There you're wrong. I made it out of heath."

"Of heath!" said Tom, bursting out laughing. "Sure you don't think me to be such a fool as to believe that?"

"Laugh if you please", said he, "but what I tell you is the truth. Did you never hear tell of the Danes?"

"Well, what about them?" said Tom.

"Why, all the about them there is is that when they were here they taught us to make beer out of the heath and the secret has been in my family ever since."

"Will you give a body a taste of your beer?" said Tom.

"I'll tell you what it is, young man, it would be fitter for you to be looking after your father's property than to be bothering decent quiet people with your foolish questions. There now, while you're idling away your time here, there's the cows have broke into the oats, and are knocking the grain all about."

Tom was taken so by surprise with this that he was just on the very point of turning round when he recollected himself. So, afraid that the like might happen again, he made a grab at the Leprechaun, and caught him up in his hand. But in his hurry he overturned the pitcher and spilled all the beer, so he could not get a taste of it to tell what sort it was. He then swore that he would kill the leprechaun if he did not show him where some secret treasure was. Tom looked so wicked and so bloody-minded that the little man was quite frightened; so says he, "Come along with me a couple fields off, and I'll show you a crock of gold."

So they went, and Tom held the Leprechaun fast in his hand, and never took his eyes from off him, though they had to cross hedges and ditches, and a crooked bit of bog, till at last they came to a great field all full of weeds, and the Leprechaun pointed to a big weed and says, "Dig under that one and you'll get the great crock all full of gold coins."

Tom in his hurry had not thought of bringing a shovel with him, so he made up his mind to run home and fetch one. To mark the spot, he took out his red handkerchief and tied it around the plant.

Then he said to the Leprechaun, "Swear ye'll not take that garter away from that plant." And the Leprechaun swore right away not to touch it.

"I suppose," said the Leprechaun, very civilly, "you have no further need of me?"

"No," says Tom, "you may go away now if you please, and may good luck attend you wherever you go."

"Well good bye to you, Tom Fitzpatrick," said the Leprechaun, "and much good may it do you when you get it."

So Tom ran for dear life, till he came home and got a shovel, and then away with him, as hard as he could go, back to the field. But when he got there, lo and behold! Every single plant in the field had a handkerchief tied round it, and every one the very model of his own. As to digging up the whole field, that was nonsense, for there was more than forty good Irish acres in it. So Tom came home again with his shovel on his shoulder, a little cooler than he went, and many's the hearty curse he gave the Leprechaun every time he thought of the neat turn he had been served.

&nsbp   Mildly adapted from "The Field of Bolians," a traditional Celtic tale.

How would we express this in terms of C++ objects? Here is an example of a set of .h files that describe a hierarchy of objects that could be used to "program" this story. (Use the following command to extract the files once you have downloaded this and placed the .tgz file in the directory you want to have the example files in.)
> tar xfz example.tgz

Note: This is a very superficial example, for a very simple story. If your assignment really was "The Field of Bolians" and this was your submission, you'd probably only get a B or a C. A better solution would have a class for Plants, a class for Location which could be inherited by Tom's house and the Field and the Hedge, etc etc. Your solution should demonstrate clearly that you understand hierarchy/inheritance, and what should go into an object.

Assignment

Most of you are familiar with the fairy tale of Little Red Riding Hood. Read through it (a common version of it can be found here) and then work up a detailed object hierarchy for this story, in the style used above for the example story. You should be turning in a directory of ".h" files which will be visually inspected but not compiled. (So they should look like valid C++ header files, although we will not be too picky about details.)