UML 2 For Dummies


Class diagrams are also used to pull together key aspects of your project—during analysis, and again during design. Accordingly, it can be helpful to create class diagrams that represent the context of the system, its problem domain, application requirements, and the design of each subsystem.

Establishing contexts

There are two kinds of context diagrams you show with class diagrams:

Use external context diagrams to scope your system (to put a boundary around your system). We use the following steps to se up an external context diagram for our system:

  1. Create a class and give it the name of the system you’re developing.

    Don’t show any attributes or operations on this class.

  2. Think about all the actors and other systems that you expect to interact with your system—and add a class to your diagram for each such interactor.

    These are your external classes.

  3. Draw an association between each interactor and your system class.

  4. Consider the multiplicity of each association.

    Ask yourself, How many instances of these actors/systems will my system interact with?

  5. Add an operation to any external class if your system must invoke its behavior.

  6. Add an attribute to any external class if that class must have some knowledge important to your system.

Internal context diagrams allow you to show internal structure. If you have a complex aggregation, then use this kind of context diagram to show the internal parts of the class. For this diagram, simply inflate the size of the class box. Place a mini-class diagram where you normally show the attributes of the inflated class. Figure 7-8 shows just such an internal context diagram for a generic report. See Chapter 5 for a detailed description for showing the internal parts of a class as a strong form of aggregation. For information about context you show using use case diagrams see Chapter 8.

Figure 7-8: Internal context diagram.

 UML2  UML 2 has a new diagram called the composite structure diagram, discussed in Chapter 5. You use composite structure diagrams to show internal context.

Creating domain classes

As you develop your system or software application, you’ll notice that you use some classes over and over again. These highly reusable classes are based on the real world and represent things in your business. In our air-filter example, classes such as Customer, AirFilter, and Coupon are found in the business world. When you talk to users, these are the very words they use when discussing their business. We call these words the domain language or the language of the user. We capture and model this user language for two reasons:

As we mention in the section “Drawing manageable class diagrams,” Figures 7-2, 7-3, 7-4, and 7-5 begin to capture the language of an air-filter order system. Users of that system understand what a coupon is, and they can look at Figure 7-5 and tell you whether you have captured all the different kinds of coupons. These four figures in this chapter are examples of domain diagrams because they describe the domain of ordering air filters in a retail setting. Your classes that capture the language of the user are known as domain classes.

Domain class diagrams that capture the user’s language are good for the following purposes:

 Tip   Develop your domain model during the requirements-gathering phase of your project. Capture in domain class diagrams what the user means as they describe what they do. Refine the domain class diagrams when the user talks about what they want your system to do for them. The very nouns the user says become classes or attributes. The verb phrases from the mouth of the user become associations.

Applying an application perspective

There comes a point in your software development when you want to show which classes come together to bring a use case to life. Remember, object- oriented software contains nothing but objects interacting together. The functionality described in a use case arises from this interaction. You need to show which objects interact to make each use case come to life. To show this relationship, use an application class diagram, which shows which classes work together to perform the job of a use case. The diagram will include a few classes from your domain diagrams as well as special classes known as application classes. Application classes have the attributes and behavior necessary to make your software live up to the description written for a use case.

The following is a list of some application classes that will help you get your project done:

These classes encapsulate the attributes and operations of your application that are “visible” to the user. The controller encapsulates what the user can do and when they can do it for your application. The view classes show things to your users. Boundary classes hide the external interactions of your application from its internal classes.

Figure 7-9 illustrates one of the application class diagrams used in an air-filter order-handling system. The attributes and operations of each class are not shown, making the diagram easier to read. You notice Figure 7-9 actually has two diagrams separated by a thick line. At the top of the figure is a use case diagram showing the review accounts use case. At the bottom of the figure is an application class diagram showing the classes that must perform the Review Accounts use case for the Order Clerk actor. (An actor is a person outside your system that interacts with your system.) The AccountReviewer knows when to access the database via the DatabaseAccessor to retrieve instances of the Customer, CreditCard, and CustomerAccount classes. The Account Reviewer also knows when, at the users request, to create instances of the view classes (CustomerView, CCView, AccountView, and ComplexAccount View) and when to ask a view to show itself to the order clerk user.

Figure 7-9: Application class diagram.

Notice that we do not draw all the associations between all the classes in Figure 7-9. The AccountReviewer controller class has associations with all the view classes because it must create them, but drawing association all of these lines clutters up the diagram and does not add anything surprising for the developer. Another reason why we may not draw the line between the AccountReviewer class and the other classes is that associations are often reserved for those situations where one class needs to continually know about another class. The more temporary the knowledge of the other class is, the more likely we don’t bother modeling it. When we use a UML modeling tool, we add these extra associations to the diagram just before we ask the modeling tool to generate code.

 Remember   All you find in object-oriented software is (you guessed it) objects. It’s the objects—not functions—that get together at runtime, collaborate, send messages to each other, and get the job done. Each use case is realized by a group of cooperating objects. Both application objects and domain objects must work together to get a use case to work.

Wrapping packages

At some point in a project, you may find that the modeling you perform to gather requirements, analyze those requirements, and develop software to meet those requirements is getting out of hand. You probably have different levels of class diagrams as well as domain class diagrams and application class diagrams. You might well be wondering how to keep it all under control. We have faced this same problem many times—and each time we used packages. You can wrap up groups of classes and even groups of diagrams into a UML package.

A package is a way of grouping classes together. A UML package looks like a tabbed file folder. You think of the package as containing certain diagrams and/or certain classes. There are several ways of organizing packages for your system:

 Tip   When your development becomes really complex and large, you can put packages inside packages.

To keep track of all those packages, use a package diagram. This diagram simply shows the packages as tabbed folders, with the name of each package on the front of each folder. You can also show any dependencies among your packages by showing a dashed line with an arrow at the end of the line up against the package some other package depends on.

 UML2   The package diagram is now an official diagram in UML 2. In previous version of UML we used a class diagram to show packages and their dependencies because there was not official package diagram separate from the class diagram in the UML modeling tool.

 Warning  Packages own their content. You can’t put the same class into two different packages. Place each class in one—and only one—package. You can use the class in other packages, but some package has to own the reused class, and that’s the only one it should occupy. See Chapter 20 for more details on organizing classes into different packages.

Figure 7-10 is a package diagram showing some of the packages you might have for the retail air-filter order-handling system. The Review Account, Handle Order, and Setup New Clients packages contain classes and diagrams that are specific to use cases by the same name. The Air Filter Domain package just contains other packages. Finally, the Client, Product, and Vendor packages contain groups of classes that are important to each of those major parts of the user’s language.

Figure 7-10: Package diagram.

Dependencies are also shown here. You see a dependency line from the Review Account package to the Air Filter Domain package. The Review Account Package is dependent on the Air Filter Domain package; to review an account, you must also use some of the classes in the Air Filter Domain package.

 Remember   Packages are a great way to group important stuff together so your complex models don’t get out of hand.


Категории