Last time we defined layers in our Layer Diagram and added projects and folders. We validated the architecture and saw that there were errors. You might already have guessed it but the explanation is, that the Layer Diagram just does not reflect the real architecture inside the source code of our example project.
Two Choices: Change Source or Diagram
We now have two choices: either we have carefully designed our layers and the errors show that the source code is not compliant, in which case we would have to change the source code, or we decide to change the layer definitions (what we will be doing for our example).
One of the really strong parts of Layer Diagrams is that they help to understand source code from a very high point of view. Imagine trying to understand the source code structure without having any documentation and just the source code. This was a time consuming task without the help of Layer Diagrams but will completely change as of today with Visual Studio 2010.
Change the Layer Diagram
Ok lets change the Layer Diagram and see what the real code structure looks like in terms of layers.
- Open the Source Code and the Layer Diagram and validate the Architecture
- Double click on the first error and you see that there are references to Business Objects (ex: ExpenseCategory) in the Presentation Layer projects
- Add a new dependency between the Presentation Layer and the Business Layer
- Re-validate the architecture and you see that there are still 29 errors, this time there seems to be dependencies inside the Data Layer that are causing the problem
- Since the Data Layer also uses Business Objects from the Business Layer we need to change the dependency from a one-way to a bidirectional dependency
- Re-validate the architecture and you see that there are still 2 errors, this time there seems to be dependencies inside the Business Layer that are causing the problem
- Since the Business Layer also uses interfaces and declarations from the Service Layer we need to change the dependency from a one-way to a bidirectional dependency
- Re-validate the architecture and you see that there are no more errors, we finally have a Layer Diagram that perfectly reflects the code structure of the source code
Summary
We saw how to use the Architecture Explorer and the Layer Diagram to build a layer structure that matches existing code or that may serve to assure, that new projects start and stay with a healthy design. We saw how to validate manually if the layer constraints are fulfilled or broken and how to fix problems.
You may even add the Architecture Validation to your build and check-in scripts in TFS. Thus automating the verification and assuring that your projects retain the initial design that your architects designed carefully.
3 comments:
My name is Deloris Moreno I was browsing internet and found your blog. The author did a great job. I will subscribe to your RSS feeds. Thank you for your contribution. I am a web designer myself. And here some examples of the websites that I designed for payday loans canada payday loans online company.
Hi
The tutorial is really good, with all the steps given.
Thanks
Gajendra
Hi, really good article.
I have a question though. I'm using these now and when I drag on my projects from Architecture Explorer none of them validate as that have Supports Validation = false?
Any idea why that is?
Adrian.
Post a Comment