Resources‎ > ‎Programming‎ > ‎Object-Oriented Design‎ > ‎OO Tutorial‎ > ‎Lesson 2‎ > ‎

Sample Solutions

Modeling

[Task]

Model "Superman".

[Facts]

 * Superman is one of superhero.
 * Superheros fight against evil.
 * Hence, Superman fights against evil.

In order to model "Superman", we will go through the basic three steps:

  1. Understand all the facts,
  2. Decide on a concept/viewpoint, and
  3. Model.

1. Understand all the facts

In order to understand the facts, you could first list all things described in the task description. Since this simple task only states "model superman", we will get more facts from the provided list.

  • Superman
  • superhero
  • fight
  • evil
  • something else?

From these facts, it seems that there are two simple themes:

  • relationship between Superman and SuperHero, and

  • relationship between Superman and Evil.

2. Decide on a concept/viewpoint

From the fact that both superman and superheros fight against evils, "fighting against evil" is the common behaviour of superman and superhero. Furthermore, you would realize that the concept of superhero is a generalized concept, and "superman" is an example (instance) of superhero.

Looks like one of important essences is:

Superman is an instance of Superhero

3. Model

We use the result ("Superman is an instance of Superhero") for deriving a model. First, we will try to model "superhero"

  • There is a class named "Superhero".
  • "Superhero" has a name.
  • "Superhero" has a behaviour "fight against Evil".

We can derive the following class (lefthand-side) and instance diagram (righthand-side).

Alternatives

Another typical modelling of Superman with respect to Superhero would be to treat Superman as a specialized version of Superhero and to model Superman as a subclass of Superhero like:

However, if this model is derived from the concept that Superman fights against evil in a different manner compared to other superheros, so it's better to have its own uniquefight().

You should think about which model would be better.

ą
Masahiro Takatsuka,
18 Mar 2012, 17:19
ą
Masahiro Takatsuka,
18 Mar 2012, 17:19
ą
Masahiro Takatsuka,
18 Mar 2012, 17:19
Comments