M  

 

The Private Site of Fariborz Moradi


 
 

We have introduced here the idea of subclasses. "Humans" was a class, and "Villains" a subclass of it.

You may also be wondering why Laura declared "Humans damsel" in this class. Think of it this way. If the villain is going to tie up a damsel, Laura's editor has to know what a damsel is. By declaring "Humans damsel", her editor will know that a damsel is a type of human.

After Laura had described what her villain looked like, she decides to move on to some of the methods (remember those from a few pages ago?) that villains employ to achieve their dastardly deeds. Being a teetotaler, Laura wants to focus on how villains drink. So she writes:

Whenever the main plot says that a villain drinks whiskey,
his level of drunkenness will go up by one.

While this may not look any different than any of the things that we were doing before, you should note that Laura is specifying how one of her characters acts, rather than just how he/she/it looks. You should also note that she is altering one of her variables here, the variable "drunkenness". Since her binders (classes)can contain information about how her characters act, Laura can create quite a bit of character development without ever even touching her main plot page.

drinkWhiskey
     drunkenness increases by one

Notice the pattern than has begun to emerge in Laura's writing. What she has done with this method is similar to how she treated variables in the past. First, she notes what she is going to describe (in this case a method called drinkWhiskey) and then, on the next line, what that method will do when she calls it in her main plot (routine).

public void drinkWhiskey()
{
     drunkenness ++;
}

Although Laura used quite a bit of strange symbols, her approach was straightforward and consistent. The first thing that she did was to name the method "drinkWhiskey". Since the method name is drinkWhiskey, Laura figures that she should modify the villain's level of drunkedness, in this case by adding one to it. That is what the "++" after "drunkedness" does.

 


 



 

 
 
 
©2006 Fariborz Moradi       Contact