The Mighty Warrior Models Classes

The Mighty Warrior Models Classes

The mighty warrior reached into her pack, and pulled out her favorite weapon, the mace Firestarter that would burst into flame upon command.  She had acquired it from a store she had visited back in the city.

She walked carefully down the hallway of the ruined castle, as quietly as she could while wearing plate armor.  She reached a doorway, and gently pushed the great stone door open.  A zombie stood just inside the room.   She quickly dispatched it with the mace.

The room contained some tattered furniture, including a bed, a small table, and two chairs.  There was also a container, a fine solid (and locked) chest.

Candidate Classes

“Wait!” cried the analyst.  “There are too many things to keep track of here.  What kinds of things are there in this place?”

Our heroine decided that it was time to create a class model.  How could she figure out what classes the game would include?  She remembered that a class represents a kind of thing, and kinds of things are described in English using common nouns.  It was time to underline all of the common nouns in the opening paragraphs.

The mighty warrior reached into her pack, and pulled out her favorite weapon, the mace Firestarter that would burst into flame upon command.  She had acquired it from a store she had visited back in the city.

She walked carefully down the hallway of the ruined castle, as quietly as she could while wearing plate armor.  She reached a doorway, and gently pushed the great stone door open.  A zombie stood just inside the room.   She quickly dispatched it with the mace.

The room contained some tattered furniture, including a bed, a small table, and two chairs.  There was also a container, a fine solid (and locked) chest.

She then took the underlined words, removed duplicates, and made a list:

Warrior

Pack

Weapon

Mace

Firestarter

Store

City

Hallway

Castle

Armor

Doorway

Door

Zombie

Room

Furniture

Bed

Table

Chair

Container

Chest

What a fine list of candidate classes!  Something bothered her about Firestarter though.  It wasn’t a kind of thing.  It was a very particular special one.  Then she remembered!  Candidate classes should only be common nouns.  Firestarter was a proper noun: it was the name of a specific object of the class Mace, not a class of its own.

Inheritance Hierarchies

Wait a second!  Was it really an object of the class Mace, or of the class Weapon?  It seemed to be both!  How could that be?

Suddenly, she had it.  Mace was a kind of Weapon.  That meant that Mace was a subclass of Weapon, which would have all of the facts and behaviors common to Weapon, and some that were special to Mace.

Were there other subclasses of Weapon?  Sure there were!  There were swords, and axes, and bows, and slings, and several more.    Perhaps each of these should be a subclass as well.

Yet somehow bows and slings were more like one another than they were like maces and swords and axes.  They each had to use projectiles (arrows and rocks), while the others didn’t.  The inheritance hierarchy was more complex yet!  Weapons could be Ranged or Melee.   Ranged Weapons could be bows or slings.  Melee Weapons could be maces or swords or axes.

Now some facts and behaviors would belong to Weapon (e.g., the behavior attack), some would belong to Ranged Weapons (e.g., how far the weapon could shoot, or what projectiles it took) or Melee, and some to specific kinds of weapon (e.g., the sword could have sharpness).

Were there other subclasses on the list!  Yes!  Bed, Chair and Table are kinds of furniture, and Chest is a kind of container.  She would have to think about other kinds of furniture and containers too.

Associations

Was that all she needed to do?  Our heroine thought back to the hallway:

The mighty warrior reached into her pack, and pulled out her favorite weapon, the mace Firestarter that would burst into flame upon command.  She had acquired it from a store she had visited back in the city.

She walked carefully down the hallway of the ruined castle, as quietly as she could while wearing plate armor.  She reached a doorway, and gently pushed the great stone door open.  A zombie stood just inside the room.   She quickly dispatched it with the mace.

The room contained some tattered furniture, including a bed, a small table, and two chairs.  There was also a container, a fine solid (and locked) chest.

Some of these clearly suggested an association between objects, and some an action taken.  She thought for a while, and organized them into two lists.

Associations:

Warrior is wearing armor

Zombie stands inside room

Room contains furniture

Actions:

Warrior reaches into pack

Warrior pulls out weapon

Mace bursts into flame

Warrior reaches doorway

Warrior pushes door open

Warrior dispatches zombie

What object had these actions?  In some sense, most of them were about unnamed associations.  A warrior could only reach into a pack if the warrior was wearing the pack, and could only pull out a weapon that was contained in that pack.  The action acted upon the object, such as the door that was pushed open.  So she needed to assign those as methods on the object class, where they could change the state of the object.

Now she was making progress!  All she need to do was start figuring out what facts she needed to track about the different classes, and then she could proceed to unlock and loot that chest!

To view or add a comment, sign in

More articles by Gary Page

  • Designing for Maintainability

    Designing for Maintainability More time and effort is spent on maintaining software than on developing it in the first…

  • What Data Should I Store: Database Design

    What Data Should I Store: Database Design Once the question of what database management system should be used is…

  • What Do I Need in a Database?

    What Do I Want In A Database? I once took a day off from my normal activities at my work to help my wife’s employer…

    1 Comment
  • Getting It Done Quick and Cheap

    Getting It Done Quick and Cheap What do you do when your boss says, “That is just too long!” or “We can’t afford…

  • My Neighbor Bob and The SDLC

    My Neighbor Bob and the SDLC One evening on the way into the house, I talked to my neighbor, Bob. In the course of our…

  • Good Requirements

    Good Requirements In order to build a system or business process to do what your company needs, someone needs to write…

  • The Mighty Warrior Gathers Information

    The Mighty Warrior Gathers Information Her long raven tresses cascading down the back of her silver armor, the mighty…

    1 Comment
  • The Information Factory

    The Information Factory Several years ago, I was working for a client who needed help planning an internal network. My…

  • Draining the Swamp

    Draining the Swamp When we try to simplify business processes, and make things more efficient, we are often surprised…

    1 Comment

Explore content categories