Class Diagrams

[article]
Testing UML Models, Part 3
Summary:

This is the third in a series of articles written to a) introduce you to the most important diagrams used in object-oriented development (use case diagrams, sequence diagrams, class diagrams, and state-transition diagrams); b) describe the UML notation used for these diagrams; and c) give you as a tester a set of practical questions you can ask to evaluate the quality of these object-oriented diagrams.

In today's testing world there is good news and bad news. The good news is that, more and more, testers are being asked to evaluate the quality of object-oriented analysis and design work earlier in the development process. The bad news is that most testers do not have an extensive background in the object-oriented paradigm or in UML (Unified Modeling Language), the notation used to document object-oriented systems.

This is the third in a series of articles written to

  • introduce you to the most important diagrams used in object-oriented development (use case diagrams, sequence diagrams, class diagrams, and state-transition diagrams)
  • describe the UML notation used for these diagrams
  • give you as a tester a set of practical questions you can ask to evaluate the quality of these object-oriented diagrams

As in the first two articles, we will use three independent approaches to test these diagrams:

  • syntax–"Does the diagram follow the rules?"
  • domain expert –Is the diagram correct?" "What else is there that is not described in this diagram?"
     
  • traceability–"Does everything in this diagram trace back correctly and completely to its predecessor?" "Is everything in the predecessor reflected completely and
    correctly in this diagram?"

For this set of articles we have been using a case study: a Web-based online auction system that I invented: f-lake. Yes, I invented the idea of online auctions. I'm not sure why f-lake never caught on.

Class Diagrams
A class diagram describes the classes that make up a system and the static relationships between them. Classes are defined in terms of their name, attributes (or data), and behaviors (or methods). The static relationships are association, aggregation, and inheritance.

The UML notation for class diagrams is shown below:

Notation
For those not familiar with the notation used for class diagrams, some explanation is in order.

Object. A specific entity or concept that has meaning in an application domain.

Class. A definition of a set of potential objects that have the same data, behavior, and relationships.

Attribute. A data value defined in a class and held within an object that has meaning within the application domain.

Behavior. A service defined in a class and provided by an object.

Method. The implementation of a behavior in an object-oriented programming language.

Association. A "peer-to-peer" relationship between classes.

Aggregation. A "whole/part" relationship between classes.

Inheritance. A "generalization/specialization" relationship between classes.

Cardinality/Multiplicity. The minimum and maximum number of objects that participate in an association or aggregation. The common (interesting) ones are 0..*, 0..1, 1..*, and 1..1

Polymorphism. The ability to send a message to an object without knowing its specific class.

Syntax Testing
Let's begin with the simplest kind of testing-syntax testing. When performing syntax testing, we are verifying that the class diagram contains correct and proper information. We ask three kinds of questions: Is it complete? Is it correct? Is it consistent?

Do you remember our secret from the previous articles? You do not need to know the answers to any of these questions before asking them. It is the process of asking and answering that is most important. Listen to the answers you are given. Are people confident about their answers? Can they explain them rationally? Or do they hem and haw and fidget in their chairs or look out the window or become defensive when you ask? Now for the questions:

Complete:

  1. Does each class define attributes, methods, relationships, and cardinality?
  2. Is each association well named?
  3. Is each association's and aggregation's cardinality correct?

Correct:

  1. Are all attributes private?
  2. Are all parameters explicit rather than

About the author

Lee Copeland's picture Lee Copeland

Lee Copeland has more than thirty years of experience in the field of software development and testing. He has worked as a programmer, development director, process improvement leader, and consultant. Based on his experience, Lee has developed and taught a number of training courses focusing on software testing and development issues. Lee is the managing technical editor for Better Software magazine, a regular columnist for StickyMinds.com, and the author of A Practitioner's Guide to Software Test Design. Contact Lee at lcopeland@sqe.com.

StickyMinds is one of the growing communities of the TechWell network.

Featuring fresh, insightful stories, TechWell.com is the place to go for what is happening in software development and delivery.  Join the conversation now!