November 20, 2010

Tool Support for Software Architecture

Support available to visualize high level models of your coding

Visual studio 2010 provides support for complete application life cycle management starting from requirements, architecture modeling to build and test automation. It also provides fully-featured UML support, integrated into the IDE which uses an extensibility mechanism that can be used to tailor UML models to a particular problem domain.
Architecture modeling is about defining the complete structure of the system. It includes defining functional, technical, data, deployment, etc. views of the system, defining logical data elements and relationships between them. In VS 2010, one can create UML diagrams in two different ways:
        Using UML model project (.modelproj)
        Using conventional .NET code project
Both above have its own features and common features to visualize high level models of the coding.

Using UML model project (.modelproj)
Newly introduced UML modeling project in VS2010 can be leveraged during Architecture modeling phase. This provide options to create new UML diagrams including Class, Sequence, Use Case, Activity, Component, Layer, Direct Graph Documents. These diagrams are used only during the modeling phase and not useful for code generation. The diagrams created through .modelproj have limitation in terms of forward and reverse engineering, which means class, sequence diagrams created under modeling project cannot generate C# or VB.NET code and vice a versa. This limits synching up code and UML models in later stages of project development.


1.      Layer Diagrams
VS 2010 has no specific diagram which captures the functional or domain or technical view of the system, layer diagrams available in architecture model helps in modeling various architecture layers of the system. Planning appropriate layering of the system is essential from scale out and extensibility perspective. If the code within the layer diagram does not adhere to dependencies established in layer diagram, it can be captured through "Architecture Validation" option provided by VS2010. Which will be very useful to architects as one doesn't have to manually review the code to catch any discrepancy in the architecture layer dependency rules defined during the architecture but violated during the development phase.
E.g. If the layer diagram establishes presentation layer cannot call data access layer directly but in case any developer implements that in the code, the layer diagram validation can help in easily isolating and correcting such code.
Although layer diagrams are not standard UML diagram types, support for layer diagrams in the VS2010 architecture modeling piece is extremely useful from .NET architect's perspective.

2.      Component Diagram
In VS2010, component diagrams are only supported through UML Models project (.modelproj) and not in .NET code project (.csproj), with this version of VS2010 reverse engineering component diagrams from code is not possible.

3.      Class Diagram
New class diagram can be created in two ways, one by creating modeling project and other from .NET projects. With UML model class diagrams in VS2010, establishing aggregation or composition relationship is supported through a dedicated aggregation, composition connector in the toolbox.

4.      Sequence Diagram
Similar to class diagrams, sequence diagrams can also be created in two ways, one through modeling project and another under .NET project. Sequence diagrams created under modeling project depicts the logical flow and doesn't provide a way to translate that into corresponding code, however sequence diagrams created under solution explorer or .NET project lets one convert diagrams into code.


Using conventional .NET code project
            If the objective of UML modeling is to generate code from UML models, then UML models should be created under .NET project. C# or VB.Net classes created under .NET projects (ASP.net, WPF, WCF library, etc) can be converted into class diagram by right clicking the code file and selecting the "View Class Diagram" option. This is supported in VS2008 and support is continued in VS2010. Similarly one can select any specific method within class file, right click and select "Generate Sequence diagram".

Below diagrams and features are also added to VS2010 to provide the support to visualize high level models of coding.

Directed Graphical Documents (DGML) Diagrams
This is very useful to understand dependency between various assemblies, components, classes across the solution or project. This also identifies any circular references in the code. DGML graphs are very useful in finding complexity or coupling within code components. Highly coupled component can be further investigated to reduce coupling amongst them.

Architecture Explorer
Architecture explorer helps in exploring the code that you want to drill down into. This feature is extremely useful in understanding and analyzing code paths, otherwise earlier this has to be explored and understood using "Go To Definition" option on right click, while doing so one used to get lost in the code.

Version Control
The Architecture models created from VS2010 can be treated similar to other code files for version management. The model project as well individual models can be check in, check out, merge, multi check out, shelved, get latest version, etc. in Team Foundation Server from Solution explorer.

Traceability
Requirements, Architecture models, code have tendency to go out of synch as soon as they get created and life after that is no different than searching a coin in a sea. As part of software development activities it is extremely important to ensure related items are associated and any change in requirement, design, code, and test is cascaded across. This is easier said than done. However support from Team  Foundation Work items helps in simplifying this.


What kind of diagrams can be reversed and forward engineered.

Code Generation from Models (Forward engineering)

Engineering projects adopting model first approach can generate code from class and sequence diagrams. As the class implementation progresses the class models can be synched up.
In model first approach, architect will create new class or sequence diagram. The new class/sequence diagram can be created by right clicking project and choosing "add new item" and then selecting class diagram or sequence diagram. Once class diagram canvas is created, one can start dragging and dropping classes, it asks for the option if you want to create class from existing .cs file or want to create new .cs file corresponding to this class. The option is useful to create multiple classes in one file or create one dedicated file for each class. As soon as one starts adding any new attributes or methods in the class from class diagram, it starts reflecting in the .cs file without any additional click, one would expect some time lag in synching up of the code with diagram but VS2010 has been able to support this extremely well and happens in a split of second.
However unlike some of the leading UML modeling tools, while modeling class diagram, VS2010 don't have support for applying standard design patterns to .NET classes.
E.g. While one is modeling classes, Singleton, Model View Controller (MVC), Façade, etc. design patterns cannot be applied directly to classes in class modeler canvas.

Generating Models from Code (Reverse Engineering)
If .NET projects have embarked on code first approach (writing code without necessarily creating various UML models) or if these models are created in other tools like Visio and code written using VS2010 then one can reverse engineer the code to generate models in VS2010.
Apart from .NET 4.0, code written in .NET 1.0, .NET 2.0, 3.0 and 3.5 frameworks can be opened in VS2010 and models can be reverse engineered from code thus providing model creation from existing code. For models to be generated, the code should cleanly compile. This feature is extremely helpful in documenting models for existing or legacy .NET applications to improve understanding of the code and in turn maintainability of the application.

No comments:

Post a Comment