当前位置:编程学习 > C#/ASP.NET >>

如何在vs.net中利用UML来建模(转自MSDN)

答案:Visually Model Software Applications
Note: Some features may not be offered in the publicly available Visual Studio.NET Beta 2.
Customers building complex distributed applications face the challenge of successfully communicating application architecture and requirements across a broad range of team members. This challenge compounds as we move into the world of loosely coupled XML Web services. It is common knowledge that the presentation of concepts and information in multiple formats—visual, spoken, written—enhances people's ability to understand messages quickly and accurately. Taking this multiple-format approach to communicating, Visual Studio.NET helps foster team coordination and productivity by providing a rich set of visual modeling tools for specifying application architecture and requirements.

An Industry-Standard Approach
Visual Studio.NET delivers support for a full range of design and modeling activities, including freeform diagramming capabilities as well as a set of industry-standard Unified Modeling Language (UML) diagrams. UML is a notation for visually describing and interpreting the pieces, relationships, and actions that comprise a software application.

With the Visual Studio.NET modeling features, users can create sophisticated diagrams to specify their application architecture and business requirements, and can communicate these across their teams. Business 易做图ysts, architects, developers—and others who want to perform 易做图ysis and design tasks to enhance communication and increase the productivity of their development teams—can take advantage of these new capabilities. The following scenario demonstrates how the structure of a particular software system can be visualized and more effectively communicated by using software models created in Visual Studio.NET.

Application Scenario: A Car Rental Software System
This scenario discusses how the eight UML diagram types might be used to model a car rental agency's software system. Beginning with three 易做图 use cases, the examples capture the core processes in the system.

Use Case Diagram
A use case specifies an interaction between a user and the system in which the user is able to achieve a goal. A typical software system might include hundreds of 易做图 use cases. Some use cases applicable to the rental agency's system are:

Customer reserves car
Before obtaining a car, a customer must make a reservation. The customer contacts the rental agency and makes a request. The agency accepts or declines the request based on a number of criteria, such as the availability of cars or the customer's rental history. If the reservation is accepted, the agency completes a form containing customer details. Payment of a deposit completes the reservation.
Customer picks up car
When the customer arrives at the agency, the rental agency allocates the model of car requested by the customer, depending on current stock levels. After paying the full fee, the customer receives the car.
Customer returns car
The customer returns the car to the agency on the day specified in the rental agreement.
The following image depicts the use-case diagram for these three use cases.


Figure 1. A 易做图 use case diagram

Static Structure (Class) Diagram
The next task is to classify the objects involved and their relationships. Examining use cases helps identify classes. Classes of objects are modeled using static structure, or class, diagrams that show the overall structure of the system, as well as relational and behavioral properties.

In a class diagram, the objects involved in the car rental system are grouped into classes. Each class contains a name section and an attribute section. Some classes also include an operations section, which specifies how objects within that class may behave.

In the Customer class, attributes include name, telephone number, driver's license number, and address. The date of birth is required to determine that the customer meets the minimum age requirement to rent a vehicle. The Customer class also stores operations, such as reservations.

Class diagrams support inheritance. In the following figure, for example, the Mechanic and Rental Agent classes inherit attributes, such as name and address, from the Employee class.


Figure 2. A static structure, or class, diagram

Sequence Diagram
A sequence diagram provides a detailed view of a use case. It shows an interaction arranged in a sequence over time, and helps to document the flow of logic within the application. The participants are shown in the context of the messages that pass between them. In a comprehensive software system, the sequence diagram can be quite detailed, and can include thousands of messages.

Suppose that a customer wants to reserve a car. The rental agent must first check the customer's records to ensure that the customer may do so. If the customer has rented a car from the company before, his or her rental history will already be recorded, and the agent need only ensure that all previous transactions ran smoothly. For example, the agent can confirm that the customer's previous rental cars were returned on time. Once the customer's rental status is approved, the rental agent can approve the car rental reservation. This process can be represented in a sequence diagram, as shown in the figure below.


Figure 3. A sequence diagram

Collaboration Diagram
A collaboration diagram is another type of interaction diagram. Like a sequence diagram, it shows how a group of objects in a use case work with one another. Each message is numbered to document the order in which it occurs.


Figure 4. A collaboration diagram

Statechart Diagram
An object's state is defined as its attributes at a particular moment. Objects move through various states as they are influenced by outside stimuli. The statechart diagram maps these states, as well as the triggering events that cause the object to be in a particular state. For example, in our rental system, the object is a car. As a car moves through the rental system, its many states produce a complex but illuminating diagram. For example, it is first added to the fleet. It remains in the state InStock until it is rented. After renting, the car is returned to the fleet and to the InStock state. At various times in its commercial life, the car may require repairs (InService). When the car reaches the end of its usefulness, it is either sold or scrapped to make way for a new vehicle.


Figure 5. A statechart diagram

Activity Diagram
An activity diagram displays the logic that occurs in response to internally generated actions. An activity diagram relates to a specific class or use case, and shows the steps involved in carrying out a particular operation.


Figure 6. An activity diagram

Component Diagram
A component diagram shows how various software subsystems make up the overall structure of the system, which is built on a centralized database that contains past rental records, car details, service records, and customer and employee details. It is critical that this data be centralized in one database, because stock levels vary by the hour and all parties must have up-to-the minute information. Keeping the data current requires real-time information updates by all parties. The software subsystems for this example include Car Records, Service Records, Sales Records, Customer Records, and Employee Records.

我看程序员(转重粒子空间)
下一个:自动生成SERVER CONTROLS在程序里的应用

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,