饭饭TXT > 学习管理 > 《Visual Studio 2010 高级编程(英文出书版)》作者:Nick Randolph/等【完结】 > [Visual.Studio.2010.高级编程].Professional.Visual.Studio.2010.txt

第 153 页

作者:Nick Randolph/等 当前章节:15387 字 更新时间:2026-6-18 14:51

what’s in this chaPter?

.

Creating models of your solution

.

Enforcing application architecture

.

Exploring existing architectures

The VSTS Architecture edition offered four diagrams for designing distributed systems, which

were almost never used by teams in production. These four diagrams have all been dropped

in Visual Studio 2010 and all of the functionality targeted for architecture tasks is brand new.

This functionality can be split into two broad categories.

The first new feature is Modeling Projects, which allow you to create UML diagrams to build

up an application model. There is also a new diagram that can be used to determine and

enforce certain relationships between code elements in your projects.

The other new features all revolve around navigating and understanding existing code bases.

This includes the ability to generate sequence diagrams from C# and VB methods, as well

as Dependency Graphs of various components in your solution. Finally, Visual Studio 2010

includes the new Architecture Explorer, which is used to quickly navigate your solution.

ModelinG ProJects

A model in software terms is an abstract representation of some process or object. You

create models to better understand and communicate to others the way different parts of the

application are intended to work. In Visual Studio 2010, you keep all of your models together

in a Modeling Project. Modeling Projects are found on their own page in the Add New Project

1062 . chaPter 54 ViSuAl STudio ulTimATe For ArchiTecTS

dialog. You can also create a new Modeling Project by adding a diagram to your solution with the

Architecture . New Diagram menu option. This brings up the Add New Diagram dialog shown

in Figure 54 - 1 . At the bottom of this dialog is a drop - down list allowing you to select an existing

Modeling Project or offering to create a new one for you.

fiGure 54 - 1

Many of the diagrams in a Modeling Project can easily be attached to Work Items in Team

Foundation Server, which makes them a great tool for communicating with the rest of the team.

The ability to create Modeling Projects and their associated diagrams is limited

to the Ultimate edition of Visual Studio 2010. The Premium edition includes the

ability to view Modeling Projects and diagrams already created by someone else.

uMl diagrams

The Unifi ed Modeling Language (UML) is an industry standard for creating diagrammatic models.

Visual Studio 2010 has the ability to create the most common UML diagrams, including Activity

Diagrams, Component Diagrams, Class Diagrams, Sequence Diagrams, and Use Case Diagrams.

The Visual Studio 2010 UML diagrams adhere to the UML 2.0 standard.

Modeling Projects .

1063

Use Case Diagrams

A Use Case Diagram (Figure 54-2) defines the

users of a system (Actors) and the tasks they

need to achieve with the system (Use Cases). As

Figure 54-2 shows, each use case can be made

up of subordinate use cases. Use Case Diagrams

are typically very high level.

Modeling Use Cases helps you to focus on the

objectives of the end users and ensure that their

needs are being met by the application that you

are providing. Additionally, it helps to identify

the boundaries of your application with respect

to the user’s needs, which is very good for

understanding the scope of what you need to build. Use Cases are typically associated with User Story

and Test Case work items within TFS.

activity Diagrams

An Activity Diagram (Figure 54-3) describes the actions and decisions that go into performing a

single task. Activity Diagrams and Use Case Diagrams are often used to show different views of the

same information. Use Cases are often better at showing the hierarchical nature of tasks that a user

performs, whereas Activity Diagrams show how each of the sub-tasks are used.

Activity begins with the small black circle and follows the arrows until they reach the circle with

the ring around it. Each rounded box is an activity and each diamond shape represents a decision

about which activity to move to next. The small fork icon in the bottom-right corner of the Search

Products activities identifies it as calling another activity.

Activity diagrams can also run activity streams in parallel as shown in Figure 54-4. This figure also

shows sending and receiving events asynchronously.

fiGure 54-2

fiGure 54-3 fiGure 54-4

Prepared for SUSAN ROERS/ email0 Susan_Krentz@aol.com Order number0 64627890 This PDF is for the purchaser’s personal use in accordance with the Wrox Terms of

Service and under US copyright as stated on this book’s copyright page. If you did not purchase this copy/ please visit www.wrox.com to purchase your own copy.

1064 .

chaPter 54 ViSuAl STudio ulTimATe For ArchiTecTS

It is common to represent algorithms as activity diagrams.

sequence Diagrams

A Sequence Diagram (Figure 54-5) shows the

messages passed between different components

in a system or between systems during some

larger activity. You use a Sequence Diagram

when you want to show the flow of activities

from one actor to another within a system.

Running along the top of the diagram are

boxes representing the different actors involved.

Running down from each actor is a dashed

lifeline on which hangs thicker execution

contexts that show where in the process each

actor is performing some operation. As you read

a sequence diagram, moving down a lifeline

equates to moving forward in time. Running

between the lifelines are messages being passed

back and forth between the different actors.

Messages can be synchronous (closed arrow) or

asynchronous (open arrow). Messages can be

found, which means that you don’t know where

they come from, or lost, which means that you

don’t know where they go. These commonly

appear at the boundaries of the activity being

modeled.

An Interaction Use (Figure 54-6) is a piece of a

Sequence Diagram that is separated out and can

be re-used. To create an Interaction Use, select

it from the Toolbox and then drag a rectangle

over the lifelines that should be involved. Once

an Interaction Use has been created, you can

use it to generate another sequence diagram or

link it to an existing one. Double-clicking an

Interaction Use opens its diagram.

fiGure 54-5

fiGure 54-6

Sometimes you need to group a few execution contexts and messages together. An example is when

you want to repeat an interaction in a loop. To do this, you need to create a Combined Fragment

(Figure 54-7) by selecting the elements that should be involved and selecting one of the Surround

With options.

Modeling Projects .

1065

fiGure 54-7

Although they both use the same notation, UML Sequence diagrams should not

be confused with .NET Sequence diagrams. UML Sequence diagrams can only

be created within Modeling Projects and can include elements from other parts

of the model. .NET Sequence diagrams are generated from existing .NET code

and are not a part of the model.

Component Diagrams

A component is a single unit of functionality

that can be replaced within its environment.

Each component hides its internal structure

but publishes provided interfaces that other

components can use to access its features.

Additionally, each component can publish a set

of required interfaces that it needs to perform

its tasks. A Component Diagram (Figure 54-8)

shows the components in a system along with

their published and required interfaces. It also

shows how published interfaces will be matched

up with required interfaces.

Modeling components helps you to think about the parts of your application as discrete units. This

in turn reduces the coupling in your design, making your application easier to maintain and evolve

going forward. You will typically model interactions between systems components (or between the

parts inside a component) with a Sequence Diagram. You can use a Class Diagram to model the

interfaces of a component along with the data that travels between the interfaces (parameters).

fiGure 54-8

1066 .

chaPter 54 ViSuAl STudio ulTimATe For ArchiTecTS

You can also use a Class Diagram to describe

the classes that make up components’ parts.

Finally, you use an Activity Diagram to model

the internal processing of a component.

Class Diagrams

A Class Diagram (Figure 54-9) allows you

to model the types in your system and the

relationships between them. These are

probably the most widely used of the UML

diagram types in the industry. You can define

classes, interfaces, and enumerations. Each

of these items can be related to each other by

inheritance, composition, aggregation, or just

association. Each item can have attributes and

operations defined on them. Finally, these items

can be grouped into packages.

fiGure 54-9

Although based on the same notation, UML Class Diagrams should not be

confused with .NET Class Diagrams. A UML Class Diagram is used to defi ne and

organize elements of the model. A .NET Class Diagram performs a similar role for

.NET code. Changing a .NET Class Diagram will alter the underlying .NET code.

uMl Model explorer

Each of the UML diagrams actually present different views of the same

underlying model. To see the entire model, you can use the UML Model

Explorer (Figure 54-10) tool window. As you add content to your model

using the various diagrams, each element will also appear in the UML

Model Explorer.

You can add items directly to the model using the context menu on

many of the nodes in the UML Model Explorer. You can also drag

elements from the Model Explorer directly onto the surface of many

diagrams. Doing this creates a link between the original element and

its appearance on the diagram. When you try to delete any element

from a UML diagram, you have the option to simply remove it from the

diagram or to remove it from the model altogether.

using layer diagrams to Verify

application architecture

A Layer Diagram (Figure 54-11) is a tool that helps you specify the high-

level structure of a software solution. It is made up of different areas or

layers of your application and defines the relationships between them.

fiGure 54-10

Modeling Projects . 1067

Each layer is a logical group of classes that commonly

share a technical responsibility, such as being used for

data access or presentation.

Once you have created a new Layer Diagram, you

can drag each layer onto the design surface and

confi gure it with a name. You can draw directed or

bidirectional dependency links between layers. A

layer depends on another layer if any of its

components have a direct reference to any of

the components in the layer it depends on. If there

is not an explicit dependency, it is assumed that no

components match this description.

fiGure 54 - 11

Once you have created a layer diagram you use it to discover communications between layers in

your compiled application and to verify that these links match the design. Before you do this, you

need to associate projects with each layer by dragging

them from the Solution Explorer and onto the layer

itself. As you do this, entries are added to the Layer

Explorer tool window (Figure 54 - 12 ) and a number

inside each layer is updated to refl ect the number of

artifacts associated with it. fiGure 54 - 12

As is shown in Figure 54 - 11 , layers can be nested inside one another.

You can create new layers by dragging projects from the Solution Explorer

directly onto the Layer Diagram surface.

Once the layer diagram has assemblies associated with it, you can fi ll in any missing dependencies

by selecting Generate Dependencies from the design surface context menu. This will analyze

the associated assemblies, building the project if necessary, and fi ll in any dependencies that are

missing. Note that the tool won ’ t ever delete unused dependencies.

When your layer diagram contains all of the layers and only the dependencies that you would

expect, you can verify that your application matches the design specifi ed by the layer diagram.

To do this, you can select Validate Architecture from the design surface context menu. The tool

will analyze your solution structure and any violations that are found will appear as build errors,

as seen in Figure 54 - 13 . Double - clicking one of these errors opens a Directed Graph showing the

relationships between the various projects.

1068 .

chaPter 54 ViSuAl STudio ulTimATe For ArchiTecTS

fiGure 54-13

Not all artifacts that can be linked to a layer diagram support validation. The

Layer Explorer window has a Supports Validation column, which can help you

determine if you have linked artifacts for which this is true.

Modeling projects have a Boolean property called ValidateArchitecture, which is used

to determine if all Layer Diagrams should be validated whenever the project is built. You can

also request that Team Foundation Build validates your architecture by adding a property called

ValidateArchitectureOnBuild to your TfsBuild.proj fi le or Process Template and setting it

to true.

linking to team foundation server

Each of the elements of a diagram in a Modeling Project, as

well as the diagrams themselves, can be linked to Work Items

in Team Foundation Server. You can do this from the context

menu of the item you would like to associate and selecting

either Create Work Item or Link to Work Item. When a model

element is associated with Work Items, it will show in the

properties window for that element (Figure 54-14). You can

also get a list of Work Items that an element is linked to by

selecting View Work Items from the element ’s context menu.

exPlorinG code

Many advanced features in Visual Studio are designed to help you understand and navigate the

structure of an existing code base. Directed Graphs give you a high-level view of the relationships

目录
设置
设置
阅读主题
字体风格
雅黑 宋体 楷书 卡通
字体大小
适中 偏大 超大
保存设置
恢复默认
手机
手机阅读
扫码获取链接,使用浏览器打开
书架同步,随时随地,手机阅读
首 页 < 上一章 章节列表 下一章 > 尾 页