Click here to Skip to main content
Click here to Skip to main content

Generate Sequence Diagram (Visual Studio)

, 24 Feb 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
Generate Sequcen Diagram

Note this feature available in Visual Studio Ultimate version.

Article is about feature provided by MS Visual Studio to generate sequence diagram from already written code.
Before getting into details how the Visual Studio does the task of generated sequence diagram, Following is describe what is sequence diagram (Following description is from Wikipedia).

Sequence Diagram
A sequence diagram is a kind of interaction diagram that shows how processes operate with one another and in what order. It is a construct of a Message Sequence Chart. A sequence diagram shows object interactions arranged in time sequence. It depicts the objects and classes involved in the scenario and the sequence of messages exchanged between the objects needed to carry out the functionality of the scenario. Sequence diagrams are typically associated with use case realizations in the Logical View of the system under development.

Read more on this : Sequence diagram

Now in the following way I designed my code and than I am going to show the sequence of this code.

View Layer



This layer of the code is View part that is going to display to the end user of the application i.e. the front end of the application.

Business Layer


This layer of the code provides business logic for the fort end part of application . This layer does all the complex activity and communicate with the datalyer.

Data Layer

This layer of the code communicate with the DataBase or Data Structure where the data is stored and bring that data out of it.

Now after doing all this For the new developer in team or to my manager I want to show the flow of code goes from front end of application and data get bring in and out of database or data structure . Flow of the code need to be cover following thing
  1. How the code flow from one layer to another layer
  2. Which classes are involved
  3. Which method of the classes are involved

So to achieve this Visual Studio provide feature to generate Sequence Diagram which gives answer to above questions.

Generate Sequence Diagram

To generate sequence diagram just right click on the method of the code and in context menu there is option Generate Sequence diagram as you see in image.

Generate Sequence Diagram Window

Once clicked on menu above dialog displayed to use which ask use to provide input for generating sequence diagram. Following are the some important parameter of it.

  • Maximum call depth - How much deep you want to go i.e. if there are more than one class involved in call and how much deep you want to go.
  • Include calls in - as the options says include class and methods of project only or full solution or full solution and external references.
  • Exclude calls to - exclude call made to property, system name space or any other namespaces.

Generated Sequence Diagram

Now once clicked on the dialog generate sequence diagram as shown in above. Above sequence diagram shows the call made to GetCustomer detail to display on front end i.e. to the user of the application.

If you see the code above in images or recall the above image code is divided in three layer and three classes involved which are respectively part of each layer.

Following steps are performed to get data from the database layer displayed by sequence diagram above.

  • View layer of application i.e. Font ask for getting customer data form business layer by calling Getcustomer method, Which is static method of business class so there is no call to create object of business layer class.
  • Business layer of application receives the call to method called GetCustomer so to fill the customer details it gives call to datalayer. But before making call it crate instance of datalayer Customer class.
  • Database layer of application receives call to the method call and in turns it make call to database and retrieve data.
  • Now database layer returns this data back to business layer customer class.
  • Business layer does the process of row data return form the datalayer and return the customer object back to view layer.
  • View layer of fetch value from the object return by business layer and display it to end user
So by the mean of generating sequence diagram I will actually able to find out flow of my code between layer, classes and methods. Also this answer the all the above question.

Note :
I specified 10 in Maximum call textbox of dialog but over here only 3 level is displayed, because as discussed my layer of coding only involve three classes of three layer.

Goto code from Sequence Diagram



With the help of generated sequence diagram by visual studio I can also jump to specify method of code directly by double clicking on the message or method call.

For example I clicked on new Customer create message or method call i.e. on the method call which marked red in above image.

Code on double click from sequence diagram


So after double clicking on the method call it directly redirect me to the code part form the generated sequence diagram.

Advantage of the Generating Sequence diagram
  • Biggest advantage of this is its helps to understand code build by some one else i.e. if you are involved in development of the project and code build by some other developer who is not part of your team and you want to find the flow of the code from start point to end point.
  • It also help you to explain code build by you and you want to explain to the other developer joining your team.
  • It displays the all classes and method called in code.
Note :
This feature generates sequence diagram from the method you clicked till end, but it doesn't display the method called before the method you selected.

For example
If I clicked on the method of business layer of my project to generate sequence diagram and it generates sequence diagram from that method i.e. from the business layer and database layer. It doesn't display those method which given call to the method on which I clicked, that means I am not able to get information from which Font end method this method is get called.

So when generated sequence diagram by clicking on the business layer method of the code discussed above, it generate sequence diagram display above. As discussed it doesn't display method of view layer which called business layer method.

Conclusion

So this cool feature of visual studio very helpful when you want to explain your own code or you want to understand code.

Thanks for reading and do post comment if you like it or something is missing or wrong.

Ref by : http://msdn.microsoft.com/en-us/library/vstudio/ee317485.aspx

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Pranay Rana
Software Developer (Senior) GMind Solusion
India India

Microsoft C# MVP (12-13)

 
Hey, I am Pranay Rana, working as a ITA in MNC. Web development in Asp.Net with C# and MS sql server are the experience tools that I have had for the past 5.5 years now.
 
For me def. of programming is : Programming is something that you do once and that get used by multiple for many years
 

You can visit my blog

StackOverFlow - http://stackoverflow.com/users/314488/pranay
My CV :- http://careers.stackoverflow.com/pranayamr
 
Awards:


Follow on   Twitter   LinkedIn

Comments and Discussions

 
Questionso you mean you have Visual studio Ultimate?? PinmemberRahman Mahmoodi24-Feb-14 21:05 
AnswerRe: so you mean you have Visual studio Ultimate?? PinprofessionalPranay Rana24-Feb-14 22:10 
QuestionVersion Specific Article PinmemberToothRobber224-Feb-14 6:21 
AnswerRe: Version Specific Article PinprofessionalPranay Rana24-Feb-14 8:41 
GeneralRe: Version Specific Article PinmemberDave Cross3-Mar-14 2:27 
GeneralRe: Version Specific Article Pinmember Forogar 7-Mar-14 10:14 
GeneralRe: Version Specific Article PinprofessionalPranay Rana9-Mar-14 9:09 
QuestionVery Cool PinmemberMike DiRenzo23-Feb-14 21:47 
AnswerRe: Very Cool PinprofessionalPranay Rana23-Feb-14 23:52 
QuestionMaybe the images are not well uploaded? Pinmemberleiyangge16-Feb-14 15:34 
AnswerRe: Maybe the images are not well uploaded? PinprofessionalPranay Rana16-Feb-14 23:01 
SuggestionChange the title of the article? PinmemberT_uRRiCA_N14-Feb-14 10:08 
GeneralRe: Change the title of the article? PinprofessionalPranay Rana16-Feb-14 23:00 
Generala very good try PinmemberSouthmountain14-Feb-14 7:03 
GeneralRe: a very good try PinprofessionalPranay Rana16-Feb-14 23:02 
QuestionNot available in all versions of Visual Studio. PinmemberBigTimber@home14-Feb-14 5:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141216.1 | Last Updated 24 Feb 2014
Article Copyright 2014 by Pranay Rana
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid