HomePractices Page 4 - Introducing UML: Object-Oriented Analysis and Design
UML Diagrams - Practices
The purpose of UML, or Unified Modeling Language, is communication; to be specific, it is to provide a comprehensive notation for communicating the requirements, architecture, implementation, deployment, and states of a system. This article will offer an overview of Object Oriented Analysis and Design, focusing in on the three most important concepts it encompasses: objects, analysis, and design. It is excerpted from the book UML Applied: A .Net Perspective, by Martin Shoemaker (Apress, 2004; ISBN: 1590590872).
UML consists of nine different diagram types, each focused on a different way to analyze and define the system. These diagrams are summarized briefly here:
Use Case Diagrams show the externally visible behavior of the system. You’ll see these in the next chapter (Chapter 2) and later on when we look at Step 1 of Five-Step UML in Chapter 6.
Activity Diagrams show an elaboration of the behavior of the system. You’ll see these in the next chapter, and use them during Step 2 of Five- Step UML in Chapter 7. A recent addition to UML is the division of Activity Diagrams into swimlanes, which you’ll see in the next chapter, and we’ll use during Step 3 of Five-Step UML in Chapter 8.
Component Diagrams show architecture of the system. You’ll see these in the next chapter, and we’ll use them during Step 4 of Five-Step UML in Chapter 9.
Sequence Diagrams show object interactions over time. We don’t use these diagrams as part of Five-Step UML, but we’ll look at them in Chapter 13.
Collaboration Diagrams show object interactions with emphasis on relations between objects. We don’t use this type of diagram as part of Five-Step UML, but we’ll look at them in Chapter 13.
Class Diagrams show class definition and relations. You’ll see these in the next chapter, and we’ll use them during Step 5 of Five-Step UML in Chapter 10.
Statechart Diagrams show state changes in response to events. We don’t use these diagrams as part of Five-Step UML, but we’ll talk about them in Chapter 13.
Deployment Diagrams show physical architecture of the system. We’ll use these in Chapter 11.
Package Diagrams show the hierarchical structure of your design. These can be useful for organizing many different types of elements and you’ll be seeing this type of diagram often throughout the book.
I have a secret. You know those different UML diagram types? Does it annoy you just a bit, having to learn so many new notations to use UML? Does it make you feel like skipping OOAD and just jumping into code?
Well, it’s true that making good UML diagrams takes some skill and some practice; but reading well-crafted diagrams is a very different matter. Just between you and me, I’ll bet you already know how to read UML diagrams, and you don’t even know it. For the rest of this chapter, I’m going to show you some examples of the different UML diagrams, and ask you a few simple questions about what it is they are saying. Don’t worry if you can’t follow all of the notation at this stage—or indeed if you find the questions too simplistic—the point of the following exercises is simply to show you how straightforward it is to read UML diagrams, and how you’ll be able to answer questions about them right away. You won’t be an expert by any measure—that comes in later chapters—but you’ll be able to understand the information contained in the diagrams.
Because, see, here’s the secret: UML—it’s all about communication . . .
An Introduction to the Kennel Management System
The exercises and examples in this book all derive from the Kennel Management System (KMS) for Sandy’s Pets, a high-tech kennel providing temporary and long-term care for cats, dogs, birds, and exotic pets. The Kennel Management System must provide familiar features tailored to the pet care domain:
Reservations and occupancy. Like a good hotel, the KMS must allow pet owners to reserve kennel space (i.e., “pens”) and to check pets in and out. Unlike a hotel, a significant fraction of the occupants reside in the kennel long term or even full time.
Exercise and grooming schedule. Like a good physical therapy clinic, the KMS must support and maintain exercise and grooming schedules for each resident. Unlike a clinic, these schedules are dictated by the pet owner rather than by a physician or therapist.
Nutrition and dietetics. Like a good health spa, the KMS must support both standard and customized diets for each resident. Unlike a health spa, some of the residents only eat live food.
Inventory and ordering. Like a good restaurant, the KMS must keep food (and other supplies) on hand to meet the needs of a varied clientele. Unlike most restaurants (and as noted previously), some of the food must be stored live.
Surveillance and tracking. Like a good day care center, the KMS must ensure that its residents are safe and secure, including allowing the pet owners to view their pets via Web cams. Unlike day care centers, each resident will be equipped with a computerized collar or tag, which will allow sensors in the kennel to locate and check the status of each pet.
Health care and medication. Like a good health care management system, the KMS must schedule regular and emergency medical visits, maintain a medical history, and manage dispensing of medications. Unlike typical health care systems, the residents come from a wide variety of species and thus need species-specific medications and treatment programs.
Customer relations and pedigrees. Like a good contact management system, the KMS must track information about residents past, present, and possibly future. Unlike typical contact management systems, the KMS must maintain information about both a pet’s parentage and future breeding plans.
The KMS must also provide basic human resources, accounting, and administration functions. For a more detailed specification of the Kennel Management System, see Appendix A.
Use Case Diagrams
A Use Case Diagram depicts actions by people and systems outside your system, along with what your system does in response. It’s useful for depicting the functional requirements of your system. Figure 1-2 shows an example of a simple Use Case Diagram for the Kennel Management System.
Figure 1-2.Use Case Diagram for care giver requirements
Excercise 101: Reading a Use Case Diagram
Answer the following questions about the diagram:
What does the KMS do when the care giver checks a pet in?
What does the KMS do when the care giver checks a pet out?
What action or actions by the care giver will cause the KMS to update a kennel assignment?
What action or actions by the Care Giver will involve the Veterinarian?
NOTE The answers to this exercise and the exercises that follow can be found at the end of the chapter.
An Activity Diagram depicts the detailed behavior inside a single functional requirement, including a primary scenario and a number of alternate scenarios. It’s useful for ensuring that you thoroughly understand a given functionality. Figure 1-3 presents an Activity Diagram for the one functional requirement of the Kennel Management System for Sandy’s Pets.
Figure 1-3.Activity Diagram for assigning a pen to a pet
Exercise 102: Reading an Activity Diagram
Answer the following questions about the diagram:
What is the sequence of steps the system performs when assigning a pen to a pet that has visited previously?
What additional steps are performed for a pet that is new to the kennel?