[ Team LiB ] Previous Section Next Section

Classification and Generalization

I often hear people talk about subtyping as the is a relationship. I urge you to beware of that way of thinking. The problem is that the phrase is a can mean different things.

Consider the following phrases.

  1. Shep is a Border Collie.

  2. A Border Collie is a Dog.

  3. Dogs are Animals.

  4. A Border Collie is a Breed.

  5. Dog is a Species.

Now try combining the phrases. If I combine phrases 1 and 2, I get "Shep is a Dog"; 2 and 3 taken together yield "Border Collies are Animals." And 1 plus 2 plus 3 gives me "Shep is an Animal." So far, so good. Now try 1 and 4: "Shep is a Breed." The combination of 2 and 5 is "A Border Collie is a Species." These are not so good.

Why can I combine some of these phrases and not others? The reason is that some are classification梩he object Shep is an instance of the type Border Collie梐nd some are generalization梩he type Border Collie is a subtype of the type Dog. Generalization is transitive; classification is not. I can combine a classification followed by a generalization but not vice versa.

I make this point to get you to be wary of is a. Using it can lead to inappropriate use of subclassing and confused responsibilities. Better tests for subtyping in this case would be the phrases "Dogs are kinds of Animals" and "Every instance of a Border Collie is an instance of a Dog."

The UML uses the generalization symbol to show generalization. If you need to show classification, use a dependency with the «instantiate» keyword.

    [ Team LiB ] Previous Section Next Section