Introducing UML: Object-Oriented Analysis and Design

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).


TIP For those who are impatient . . .
If you already understand objects, you don’t need convincing that UML is a great thing, and you just want to start learning the UML notation right away, skip ahead to Chapter 2.

IN UML, the L is for language, one of the definitions of which is “any means of communicating,” according to the Merriam-Webster Dictionary. That is the single overriding purpose of UML, or the Unified Modeling Language: to provide a comprehensive notation for communicating the requirements, architecture, implementation, deployment, and states of a system.

UML communicates these aspects from the particular perspective of Object Orientation (OO), in which everything is described in terms of objects: the actions that objects take, the relationships between the objects, the deployment of the objects, and the way the states of the objects change in response to external events.

The starting point in this chapter will be an overview of Object-Oriented Analysis and Design (OOAD), focusing in on the three most important concepts it encompasses—objects, analysis, design—because to understand UML, you first must understand these broader concepts. If you’ve programmed with any OO language, then you’re probably already familiar with a lot of these ideas, so I’ll keep this discussion brief. Besides, a full discussion of OOAD is beyond the scope of this book. If you want to explore OOAD further, you should read Booch’s Object-Oriented Analysis and Design with Applications.1

Next, I’ll discuss the results of the OOAD process, namely, a model. I’ll take a bit of a diversion to discuss the nature of models, how you use them, and why they’re important.

For the rest of the chapter, I’ll be focusing on UML, looking at what it is, and— perhaps more importantly—what it isn’t. But before I get started into the nitty gritty of all the different UML elements and diagrams and what the notation looks like (I’ll save that for the next chapter!), I’ll be showing you some UML diagrams from the case study that I’ll be developing in detail in the next part of the book. Now these diagrams aren’t there to scare you off: quite the contrary. When you start to look at some real-world UML, you’ll see how intuitive it is, and how you can understand much of it without any formal teaching.

Objects

Many modern programming languages depend largely or exclusively on the concept of objects: a close syntactic binding of data to the operations that can be performed upon that data. In these Object-Oriented languages—C++, C#, Java, Eiffel, Smalltalk, Visual Basic .NET, Perl, and many others—programmers create classes, each of which defines the behavior and structure of a number of similar objects. Then they write code that creates and manipulates objects that are instances of those classes.

One reason why objects are a powerful programming technique—the reason most often touted in the early literature on Object-Oriented Programming— is that programmatic objects map naturally to real-world objects. Suppose, for example, that your company has to deal with orders. These orders would probably have an ID number and contain information on products. You could create Order objects, which would map to these real-world objects, and which would have properties such as ID and ProductList. You’d probably want to be able to add a product to the order and to submit the order, so you could write AddProduct and SubmitOrder methods. This mapping between objects in the real world and more abstract code objects encourages programmers to think in the problem domain, rather than in computer science terms. This benefit has perhaps been overstated, however; unless you’re building a simulator of a real-world process, such surrogate “real-world” objects form just the surface of your system. The complexity of your design lies underneath that surface, in code that reflects business rules, resource allocation, algorithms, and other computer science concerns. If you only use objects to reflect the real world, you leave yourself with a lot of work.

A more important benefit of classes and objects is that they form a nice syntactic mechanism for achieving some classic aspects of well-designed code:2

Encapsulation. The goal of encapsulation is to expose only enough of a module or subsystem to allow other modules to make use of it. Object-Oriented Programming allows you to specify the degree of visibility of elements of your code, so that client code is restricted in what it can access. Thus, you can syntactically seal off implementation details, leading to more flexibility and maintainability in your system.

Loose coupling. Coupling refers to the ways in which and degrees to which one part of the system relies on the details of another part. The tighter the coupling, the more changes in one part of the system will ripple throughout the system. With loose coupling, the interfaces between subsystems are well defined and restricted. What lies beyond those interfaces can change without any changes needed in the client sub systems. Object-Oriented Programming supports loose coupling by allowing you to define and publish a class’s methods without publishing how those methods are carried out. This principle goes even further in OO languages that support interfaces (described later in this section).

Strong cohesion. Cohesion refers to the degree in which elements within a subsystem form a single, unified concept, with no excess elements. Where there is high cohesion, there is easier comprehension and thus more reliable code. Object-Oriented Programming supports strong cohesion by allowing you to design classes in which the data and the functions that operate on them are tightly bound together.

Does OO force you to have these quality attributes in your code? I wish! No matter the language, you can write shoddy code with no encapsulation, pathological coupling, and no cohesion. Furthermore, some OO languages are less rigid than others in how much they require you to design around objects. But OO languages certainly support these quality attributes if you take the time to pursue them.

The key concepts in Object-Oriented Programming are these:

Classes. A class is the definition of the behavior and properties of one or more objects within your system. A class binds the data (attributes) of an object to the behavior (operations) that it can perform.

Attributes. An attribute is a data value or state that describes an object and helps you to tell one object from another of the same class. It seems that every new OO language author feels the need to distinguish their language by coming up with new terminology. In some OO languages, these data values are called properties or member variables or member data; but in UML, the proper term is attributes.

Operations. An operation is a behavior or function that an object can perform. Depending on the OO language, these might be called methods or member functions or even messages. The last term, messages, comes from Smalltalk, one of the earliest OO languages, in which all objects communicated by sending messages to each other. You’ll see a similar use of the term message when we study Sequence Diagrams.

Objects. An object is an instance or specific example of a class. If Dog is the class, then Betsy, Ladi, Patches, Jake, Radar, and Frosty are specific instances of the class found in my house. The attributes of the class have specific values within an object of that class; and the operations of a class operate on the attributes of individual objects.

Inheritance. This concept indicates that one class (the superclass) provides some common or general behavior inherited by one or more specific classes (the subclasses). The subclasses then provide more or different behavior beyond that defined in the superclass. For example, besides the Dogs, I have Cat objects and Horse objects that live on my property. Each class has unique behaviors: Dogs must be walked, Cats use the litter box, and Horses drop manure that must be scooped up and thrown in the manure pile. Yet all classes have some common behavior: they must be fed, and they must have vet visits. So I can define a superclass, Pet, and have my subclasses, Dog, Cat, and Horse, derive their shared behavior from the Pet class. In UML, this concept is known under the slightly different term of generalization, in which a superclass provides the generalized behavior of the subclasses. It’s really the same concept, but just looking at it the other way up.

Components. A component is a collection of related classes that together provide a larger set of services. Components in your system might include applications, libraries, ActiveX controls, JavaBeans, daemons, and services. In the .NET environment, most of your projects will require component development.

Interfaces. An interface is a definition of a set of services provided by a component or by a class. This allows further encapsulation: the author of a component can publish just the interfaces to the component, completely hiding any implementation details.

Each of these concepts will be explored in more detail as I discuss the UML diagrams that represent them.

{mospagebreak title=Analysis}

In software development, analysis is the process of studying and defining the problem to be resolved. (We all define the problem before we start solving it, right? Right? Oh, please, somebody say “Right!” We can’t all be that screwed up, can we?) It involves discovering the requirements that the system must perform, the underlying assumptions with which it must fit, and the criteria by which it will be judged a success or failure.

Object-Oriented Analysis (OOA), then, is the process of defining the problem in terms of objects: real-world objects with which the system must interact, and candidate software objects used to explore various solution alternatives. The natural fit of programming objects to real-world objects has a big impact here: you can define all of your real-world objects in terms of their classes, attributes, and operations.

Design

If analysis means defining the problem, then design is the process of defining the solution. It involves defining the ways in which the system satisfies each of the requirements identified during analysis.

Object-Oriented Design (OOD), then, is the process of defining the components, interfaces, objects, classes, attributes, and operations that will satisfy the requirements. You typically start with the candidate objects defined during analysis, but add much more rigor to their definitions. Then you add or change objects as needed to refine a solution. In large systems, design usually occurs at two scales: architectural design, defining the components from which the system is composed; and component design, defining the classes and interfaces within a component.

Models

Did you ever build a model ship? When I was young, my mom and I built a model of the famous clipper ship Cutty Sark.3 I’ve always been fascinated by the tall ships of old; but I really learned about how they work when we built that model. All of the strange nautical terminology from the old pirate movies—forecastle, capstan, main mast, and especially belaying pins (“You mean they’re not just there so somebody can pull one out and swing it as a club?”)—gained concrete meaning when I assembled them and saw them in the context of the entire system.

Well, that’s a central goal of using UML in OOAD: to let you study and understand a system via a model of that system. Like aerodynamic engineers, construction architects, and others in the physical engineering world, you’ll build models of systems yet to be built, not just models of existing systems. Your models will let you explore design alternatives and test your understanding of the system at a much faster rate and much lower cost than the rate and cost associated with actually building the system.

“But wait a minute!” the skeptic in the crowd shouts. “I can see the Cutty Sark, if I travel to London. And I can see the model Cutty Sark, if I visit your home. I can look at the two, and see how the model relates to the real thing. But I can’t ‘look at’ software, except at its user interface. So your model looks like the UI? Isn’t that just a prototype?” That’s the problem with the usual engineering model analogy as applied to software models: there’s no direct physical correspondence between the model and the final product. A better analogy is to models in less tangible scientific disciplines. Quantum physics is a good example of a field in which models help you to understand things you can’t see: no one can see quarks or leptons or hadrons or any of the many subatomic particles; and attributes like charm and strangeness have only metaphorical meaning. The models of quantum physics aren’t literally true, yet they’re very useful in understanding physical phenomena. Software models are like that: useful metaphors and abstractions to help you think about a problem and a solution, not literal depictions of the code itself.

In the case of OOAD with UML, your models consist primarily of diagrams: static diagrams that depict the structure of the system, and dynamic diagrams that depict the behavior of the system. With the dynamic diagrams, you can trace through the behavior and analyze how various scenarios play out. With the static diagrams, you can ensure that each component or class has access to the interfaces and information that it needs to carry out its responsibilities. And it’s very easy to make changes in these models: adding or moving or deleting a line takes moments; and reviewing the change in a diagram takes minutes. Contrast that with actually building the code: hours to implement the change, hours more to test and review it.

But remember The Model Rule:

To use UML effectively, you should never be simply drawing pretty pictures; you should always be editing an underlying model, using the pretty pictures as your user interface.

Your core artifact of the OOAD process is the model. In fact, you will likely have multiple models:

  • Analysis Model. This is a model of the existing system, the end user’s requirements, and a high-level understanding of a possible solution to those requirements.

  • Architecture Model. This is an evolving model of the structure of the solution to the requirements defined in the Analysis Model. Its primary focus is on the architecture: the components, interfaces, and structure of the solution; the deployment of that structure across nodes; and the trade-offs and decisions that led up to that structure.

  • Component (Design) Models. This is a number of models (roughly, one per component) that depict the internal structure of the pieces of the Architecture Model. Each Component Model focuses on the detailed class structure of its component, and allows the design team to precisely specify the attributes, operations, dependencies, and behaviors of its classes.

Depending on your development process, you may have even more models: a Business Model, a Domain Model, possibly others. The major benefit of models is that you can make model changes far earlier in the development cycle than you can make code changes, and far easier. And because you can make changes early, you can make your mistakes early. And that’s a good thing, because early detection and correction is cheap detection and correction. Modeling will let you catch your most costly bugs early; and early detection and correction can save you a factor of 50 to 200 on the cost and schedule of a bug fix.4


Equal Time for an Extreme Perspective

Although software engineering literature is rife with research that demonstrates that the cost to fix a defect rises catastrophically over time, those in the Extreme Programming camp disagree. They argue that all such research is dated, and that modern development tools and techniques allow a maximum limit to the cost of change.5 They see not an exponential growth, but an asymptotic approach, as shown in Figure 1-1.


Figure 1-1.  Cost to correct defects over time 

To which theory I can only reply, “So?”

  • First, their theory is a prediction, not a guarantee: if you apply the techniques they advocate and if you do everything correctly and if you are working in the right sort of environment on the right sort of project, then the lessons of 30 years of software engineering will allow you to attain the asymptotic curve. Good for you, if you can do that; but the exponential curve is the default behavior. (Furthermore, I would argue that modeling is a useful tool for attaining that asymptotic curve.)

  • Second, look at those curves. Do you want to argue over which curve is “right” at the 8-weeks mark? Or would you rather just fix the problem at the 1-week mark? (Beck argues that there is benefit in waiting for the latest possible time, so that you have the maximum information when you make the fix and also so that you don’t waste time fixing problems that never really arise; but his actual example shows the benefits of making a change as soon as you are aware of it. These concerns aren’t incompatible.)


Modeling has another benefit, one I call The Outline Effect. Back in high school, I never needed study habits: I liked to read, and I liked to learn, so school came easy to me at my small rural high school. Then I went to a Big Ten university, and reality came crashing in on me. I didn’t understand that learning at that level was supposed to be work, a job you tackled in a systematic fashion with specific goals and strategies. My “strategy” was sort of like code-and-fix: just tackle whatever came along, and hope it all worked out. It didn’t, and I didn’t understand why. Every night, I sat in my room, reading the textbooks  . . until something distracted me, which happened far too often. Meanwhile, every night, a friend sat in his room across the hall, outlining the textbooks. And surprise—he had a much better GPA than I did.

It took me years to appreciate my friend’s study skills. The process of outlining the text forced him to focus: he had a concrete goal in mind, and wouldn’t allow distractions until he finished it. Furthermore, the outlining involved more of his brain: in order to produce an outline of the textbook, he first had to comprehend the textbook; and then to actually write the outline in his own words, he had to involve yet more areas of his brain, as he had to formulate what he wanted to write. Heck, he even had to involve his tactile and motor areas of his brain in order to write the words. He had a much more fully involved brain, and thus he much more fully understood the material.

This is a benefit you can gain from modeling: by listening and talking and reading and by then translating what you learn into a model, you learn it more thoroughly. This is even more important in system design than in studying from a textbook: in a textbook, you expect that the text will be more or less consistent, and that any seeming inconsistency is most likely a sign of something you misunderstood; but in requirements gathering, contradiction and inconsistency are inevitable parts of the process. By modeling the requirements, you may highlight the inconsistencies, particularly when you gather details from many different parts of a specification and put them together in the same diagram.

And there’s one more modeling benefit, one I believe I may have mentioned earlier: communication. It’s easier to communicate with models than with text, or even with code; and you can communicate with a wider audience with models than with other forms of expression. Once you’ve created a diagram “in your own words,” I can more easily comprehend how you comprehend things by comparing your diagram with what I comprehend.

{mospagebreak title=UML}

UML, the Unified Modeling Language, is a graphical language designed to capture the artifacts of an OOAD process. It provides a comprehensive notation for communicating the requirements, behavior, architecture, and realization of an Object-Oriented design. As you saw in the last section, UML provides you with a way to create and document a model of a system.

What Makes the UML Unified?

To answer that, you need to jump in the WayBack Machine and travel back to the ancient history of OOAD—say, 1995. At that time, Object-Oriented Programming had proven its worth as a way of building applications and systems; and the hot new topics in the OO world were OOA and OOD. Since these topics were larger in scope than mere programming, the practitioners needed a way of displaying large, complex concepts in a simple graphical fashion. A number of competing OO notations emerged, chief among them being the Booch Notation designed by Grady Booch and the Object Modeling Technique (OMT) designed by James Rumbaugh (and others). And then began the religious wars: fanatical adherents of the competing notations fought petty little battles over clouds (Booch’s symbol for a class) versus rectangles (OMT’s symbol for a class).

Booch and Rumbaugh looked on this confusion with dismay: they saw the differences between their notations as minor, unworthy of so much rancor. And worse, they saw the religious wars detracting from what they felt should be the new focus: the OOAD process itself, particularly as a means for capturing requirements and behavior. They were very impressed by some of Ivar Jacobson’s work on Sequence Diagrams and his Objectory methodology; but with all the shouting about notation, no one was talking about process. So Booch and Rumbaugh and Jacobson (the Three Amigos) went on retreat to hammer out differences in their notations in private, and to adopt other useful notations as well (chief among these being David Harel’s State Diagram notation). They emerged with the Unified Modeling Language 0.8, a response to the Object Management Group’s call for a standard object modeling notation; and Booch’s company, Rational6 (which had hired Rumbaugh and Jacobson) incorporated UML into Rational ROSE, their OOAD tool. The UML then went through a few cycles of response and revision by the OO community; and UML 1.1 was adopted as a standard by the OMG in 1997. UML has been further refined, and is currently at version 1.4, with version 2.0 on the near horizon.

What UML Isn’t

With so much in UML, it’s worth mentioning what’s not UML. The following sections describe some related concepts that are often confused with UML itself.

A Process

Remember the goal of the Three Amigos: to focus attention on the OOAD process, not on the notation. Their notation isn’t a process in itself; rather, it’s designed to support a wide range of OO processes. There are a number of UML-based OOAD processes, including Fowler’s outline process,7 controlled iteration,8 Texel and Williams’s complete OO process,9 and, of course, the Unified Process (formerly Objectory) from the Three Amigos.10 A full list would be much longer, but would have a lot in common with these prominent examples. These processes differ somewhat in the degree of formality and the order of operations; but all involve using UML to identify and refine requirements, allocate those requirements to functional modules, and refine those modules. Without a process, new UML students are often adrift in a sea of concepts, with nothing to guide their course.

In this book, you’ll learn UML within the framework of Five-Step UML, which I find to be a “just enough” process: just enough process to help you understand the purpose of UML, but not so much as to bury you in paperwork and obscure the benefits of UML. Five-Step UML isn’t a large, full-featured OOAD process, falling somewhere between an academic exercise and Ambler’s Agile Modeling.11 Still, I find that some particularly process-averse teams that tend to reject a more formal process will accept Five-Step UML.

In the next chapter, I’ll show you how the Five-Step process works, and along the way, you should pick up a broad working knowledge of UML. In Chapter 3, I’ll talk about some pragmatic rules I like to apply to the Five-Step (and indeed any other) modeling process. Throughout the core chapters of this book (Part Two), we’ll work through each of the five steps in more detail, applying it to a real-world case study. Although the focus of this book is on Five-Step UML, we will look in more detail at some other processes and how they work in Chapter 12.

Rational XDE (or Any Other Tool)

Many UML practitioners—and of course, many UML tool vendors—tend to blur the line between UML and a given tool. I myself am prone to equating “what XDE can do” with “what UML can do,” since I do most of my UML work with Rational’s XDE tool. This habit isn’t inherently bad, since it’s usually easier to work with your tools than against them; but it’s important to realize that the features and capabilities of any given tool—even the market-leading UML tool from the people who gave us UML—may differ from the features and capabilities of UML itself. If UML is a language, then every tool speaks with a unique accent.

You can find a list of available UML tools in Appendix B.

A Silver Bullet

Good code will still require blood, sweat, tears, pizza, good management, and lots of thought. UML will help you to organize these factors (except the pizza), but you won’t be able to avoid them.

{mospagebreak title=UML Diagrams}

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:

  1. What does the KMS do when the care giver checks a pet in?

  2. What does the KMS do when the care giver checks a pet out?

  3. What action or actions by the care giver will cause the KMS to update a kennel assignment?

  4. 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.

Activity Diagrams

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:

  1. What is the sequence of steps the system performs when assigning a pen to a pet that has visited previously?

  2. What additional steps are performed for a pet that is new to the kennel?


{mospagebreak title=Component Diagrams}

A Component Diagram depicts the deployable units of your system—executables, components, data stores, among others—and the interfaces through which they interact. It’s useful for exploring the architecture of your system. Figure 1-4 presents an example of a Component Diagram for the Kennel Management System.


Figure 1-4.  Component Diagram of the Kennel Management System

Exercise 103:  Reading a Component Diagram

Answer the following questions about the diagram:

  1. The Care Giver Center is the Web page that the care giver uses to enter information about a pet. What interface does it use to provide data to the KMS?

  2. What other components provide data to the KMS, and through what interfaces?

  3. What types of contacts can be made through the Comm Center component?


Sequence Diagrams

A Sequence Diagram depicts the detailed behavior over time within one path or scenario of a single functional requirement. It’s useful for understanding the flow of messages between elements of your system. Figure 1-5 presents an example of a Sequence Diagram for the Kennel Management System.


Figure 1-5.  Sequence Diagram for creating a vet record

Exercise 104:  Reading a Sequence Diagram

Answer the following questions about the diagram:

  1. Which objects in the system are involved in creating a vet record?

  2. Which actors outside the system are involved in creating a vet record?

  3. What interface does the Vet Record Page use for creating a vet record?

  4. How does the system contact the veterinarian?


Class Diagrams

A Class Diagram depicts the classes and interfaces within the design of your system, as well as the relations between them. It’s useful for defining the internal, Object-Oriented structure of your code. Figure 1-6 presents an example Class Diagram from the Kennel Management System.


Figure 1-6.  Class Diagram for Kennel assignment


NOTE  You’ll probably notice here the two different sorts of connection between the classes. Here, the solid lines depict an association, whereas the dashed line depicts a dependency. I’ll discuss what this means in detail in the next chapter.

Exercise 105:  Reading a Class Diagram

Answer the following questions about the diagram:

  1. What three classes are associated with the Kennel Assignment class?

  2. What operations can objects of the Kennel Assignment class perform?

  3. What attributes describe an object of the Pet Record class?

  4. What attributes describe an object of the Kennel Space class?


Statechart Diagrams

A Statechart Diagram depicts how the state of your system changes in response to internal and external events. It’s useful for ensuring that each event is handled properly no matter what state your system may be in. Figure 1-7 presents an example of a Statechart Diagram from the Kennel Management System. This diagram illustrates events involving the availability of kennel spaces.


Figure 1-7.  Statechart Diagram for Kennel Spaces

Exercise 106:  Reading a Statechart Diagram

Answer the following questions about the diagram:

  1. What event causes a kennel space, or pen, to enter the Defined state?

  2. What events (from which states) cause a pen to enter the Available state?

  3. What state does a pen enter when it’s currently in the Available state, and a Dismantled event occurs?

  4. How can a pen go from the In Use state to the Deconstructed state?


Deployment Diagrams

A Deployment Diagram depicts how the deployable units of your system—applications, components, data stores, etc.—are assigned to various nodes, as well as how the nodes communicate with each other and with devices. It’s useful both as a map of your system and as a means for studying the load across your system. Figure 1-8 presents a simple example of a Deployment Diagram for the Kennel Management System.  


Figure 1-8.  Deployment Diagram for the Kennel Management System

 Exercise 107:  Reading a Deployment Diagram

Answer the following questions about the diagram:

  1. Which processes are running on the reception station?

  2. How is the KMS server connected to the telephone?

  3. How does the owner’s PC access pet information on the KMS server?

  4. How does information go from the care giver station to the reception station?


{mospagebreak title=Package Diagrams}

A Package Diagram depicts how related elements of your design are grouped together, as well as how the groups depend upon each other. It’s useful for dividing a complex design into multiple, more manageable smaller designs. Figure 1-9 presents an example of a Package Diagram from the Kennel Management System.   


Figure 1-9.  Package Diagram of the Kennel Management System

Exercise 108:  Reading a Package Diagram

Answer the following questions about the diagram:

  1. Which packages make use of information from the KMS Interfaces package?

  2. Which packages does the KMS Central Classes package make use of?



“Wait a Minute! Those Arrows Are Pointing in the Wrong Direction!”

An Apology to Database Modelers and Data Flow Diagrammers

If you come from the database-modeling world and are used to entity relationship diagrams (ERDs), you probably got Exercise 108 exactly wrong. The same is probably true if you come from the world of data flow diagrams (DFDs). In both of those diagramming techniques, the arrows on a diagram indicate the direction of data flow. In UML, the dependency arrows (- – – – >) indicate the direction of knowledge and control. To those people familiar with ERDs and DFDs, this seems exactly backwards. Their instinct is to interpret Figure 1-9 as meaning that KMS Interfaces make use of Care Giver Classes, Accounting Classes, Reservation Classes, and KMS Central Classes.

The UML convention isn’t quite as backwards as it seems. How would a class in Care Giver Classes make use of an interface in KMS Interfaces? By calling its methods, of course. And very likely, the class would pass data to the interface as well. So control and even some data do indeed flow in the direction of the dependency arrow.

And if that doesn’t help you to keep the meaning of the arrows straight, I can only apologize, and claim innocence: I didn’t write the UML (though its convention seems “correct” in my biased perspective). I do know that this is a source of confusion for ERD and DFD practitioners; and I hope that this warning will help to minimize your confusion.


{mospagebreak title=It’s All About Communication}

I hope that the exercises in this chapter have eliminated any mystique about UML in your mind; but even more, I hope that I have set an example of how UML can be used to communicate ideas. The underlying point for this section and the whole book is this: UML is about communication.

Don’t worry about being perfect all at once (or ever!). If you’re communicating, you’re using UML effectively. There’s always room for improvement; but don’t let imperfection stop you from progress. That’s a key point in learning and applying UML and in applying UML as part of a process. Your designs won’t be perfect; but as your team reviews them and you refine them, they will become good enough: good enough to build the system, good enough to guide the testing and the documentation, good enough to drive the management of the process. A team that waits for perfection is just as bad as a team that is wedded to code-and-fix: neither team produces an effective design that leads to a successful system. Remember: code-and-fix bad; design-and-fix good.


Letting Go of Perfection: A Lesson from the Graphic Arts

If I haven’t persuaded you yet to let go of perfection, it won’t surprise me. It’s easy for me to say that you can make imperfect diagrams and improve them later; but how do you do it? How do you just sit down and start drawing diagrams when there’s nothing you know? I hear this most often from students who are drawing Sequence or Activity Diagrams: “How can I draw this diagram until I know which objects are in the system?” And they have it exactly backwards: they’ll use the diagrams to discover objects that solve the problem. But they want to draw the right picture. Maybe they’re afraid to look foolish in reviews. (Reviews can be intimidating even to a strong ego like mine!) Maybe they’re just hypersensitive to the risks in the wrong design. Maybe they have embraced the idea that the design is supposed to help them get things right, and therefore are reluctant to risk getting things wrong. But whatever the reason, they just can’t seem to let go.

So I try a different approach. My students who have seen me sketch diagrams at the flip chart are very aware that one thing I’m not is an artist. But borrowing a technique from the graphic arts,12 I draw the images shown in Figure 1-10, one on top of another.


Figure 1-10.
  Refining from imperfect to communication

The technique is simple: put down some detail—even if it’s wrong, such as the sizing circles in the first image —to serve as a basis for further development; then add and erase detail as needed to refine the picture. I’m still not an artist (I draw fencers because the hard parts are hidden behind a mask and a weapon); but by applying some simple techniques and refining, I end up with a much more recognizable picture than I would have if I sat down and tried to draw a perfect fencer from scratch. Imperfection and refinement produces better (and faster!) results than does a foolish insistence on perfection.

Scott Adams tells us, “Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.”13 Take this attitude to heart in your analysis and design process.


{mospagebreak title=Summary}

I began this chapter with a quick overview of some of the main concepts underpinning Object-Oriented development and seeing how these apply to the process of Analysis and Design. Next, I discussed how modeling can help you not only design a better system, but also develop a better understanding of that system and how it should work.

In the second half of this chapter, we dipped our toes in the waters of UML— taking a quick look at some of the different types of diagram—but it’ll be time to jump right in during the next chapter.

Exercise Solutions

Solutions to Exercise 101

  1. The system creates a kennel assignment, a mapping of a pet to a specific pen.

  2. The system closes the kennel assignment.

  3. Checking a pet in or checking a pet out.

  4. Logging a medical problem.

Solutions to Exercise 102

  1. Enter the pet’s name. Find available kennel space. Assign the kennel to the pet.

  2. Enter the pet’s personal data. Create a new record for the pet.

Solutions to Exercise 103

   1.  ICareGiving.

    2.  Reservation Center through the IReservations interface. 
        Accounting Center through the IAccounting interface.

    3.  Intercom, telephone, email, and postal.

Solutions to Exercise 104

   1.  Care Giver Center, Vet Record Page, ICareGiving interface,  
        and ICommunications interface.

   2.  Care Giver and Veterinarian.

    3.  ICareGiving.

   4.  Via a telephone contact.

Solutions to Exercise 105

  1. Pet Record, Reservation Record, and Kennel Space.

  2. Create and Close.

  3. Name, Species, Breed, Owner, and Schedule.

  4. Kennel Number, Building, Size, and Status.

Solutions to Exercise 106

  1. Specifications Completed.

  2. Construction Completed (from Defined), Pet Checked Out (from In Use), and Pet Relocated (also from In Use).

  3. Deconstructed.

   4. Via a Pet Checked Out event or a Pet Relocated event,
       followed by a Dismantled event. This prevents the system from
       having a pet with no defined pen. (Can’t have the dogs running
       loose!)

Solutions to Exercise 107

  1. Accounting center and reception center.

  2. Via the modem.

  3. Via the Internet.

  4. According to this diagram, the only path possible is through the KMS server. Although the diagram doesn’t explicitly state this, the likely approach is that the care giver station updates information in the central database, and the reception center reads this updated data.

Solutions to Exercise 108

  1. Care Giver Classes, Accounting Classes, Reservation Classes, and KMS Central Classes.

  2. KMS Interfaces and KMS Database Classes.


    1. Grady Booch, Object-Oriented Analysis and Design with
       Applications
, Second Edition (Addison-Wesley, 1994). This is the
       classic work on OOAD, and a must-read.

    2. Steve McConnell, Code Complete: A Practical Handbook of 
       Software Construction
(Microsoft Press, 1993), pp. 81–93, 116–
       130, 150. McConnell provides far more information
on code 
       design than I can cover here.

   3. See http://www.cuttysark.org.uk/ for pictures and the history
       of this vessel.   

   4. Steve McConnell, Software Project Survival Guide (Microsoft
       Press, 1997), p. 29

   5. Kent Beck, Extreme Programming Explained: Embrace Change 
      (Addison Wesley, 1999),
pp. 21–25

   6. In December 2002, Rational became a division of IBM Corporation.

   7. Martin Fowler and Kendall Scott, UML Distilled, Second Edition
      (Addison-Wesley, 1999), pp. 13–38

   8. Murray R. Cantor, Object-Oriented Project Management with UML
      (John Wiley & Sons, 1998), pp. 98–103

   9. Putnam P. Texel and Charles B. Williams, Use Cases Combined
      with Booch/OMT/UML: Process and Products
(Prentice Hall,
      1997), pp. 3–9ff.

 10. Ivar Jacoboson, Grady Booch, and James Rumbaugh, The Unified
      Software Development Process
(Addison-Wesley, 1999)

 11. Scott W. Ambler, Agile Modeling: Effective Practices for eXtreme
      Programming and the
Unified Process
(John Wiley & Sons, 2002)

 12. Klutz Press Editors, Draw the Marvel Comics Super Heroes (Klutz
      Press, 1995), pp. 20–32

13. Scott Adams, The Dilbert Principle (HarperBusiness, 1997), p. 324

[gp-comments width="770" linklove="off" ]

chat sex hikayeleri Ensest hikaye