Showing posts with label Models. Show all posts
Showing posts with label Models. Show all posts

Sunday, 23 June 2013

Visual Studio Tricks - UML Validation of your Intended Architecture



Now for the third post from the series of Visual Studio Tools I Can't Live Without on using UML diagrams to validate your intended architecture.

Part of what I do when I run a code review is to extend it with a report on design divergence. That is when I look at what the intended application design was and what has actually been implemented.

This takes several long and probing interviews with the application architect or technical lead, asking questions about what they think has been coded. Then I look at the code at a high level, with more attention paid to sections with more complexity.

Sometimes it is pretty spot on. Sometimes it is very very different when we get in to the code.

As mentioned in other posts, I will use tools like dependency graphs to get a quick high level understanding of a code base. Another tool that Visual Studio gives me that I didn't have in the past is UML diagram validation of code.

Visual Studio has a project type called a Modelling Project that allows you to create different kinds of UML diagrams that communicate what your intended application design is or are created from code and show the implemented application design.

Again, there is a lot of documentation on how to create these diagrams. The main thing to know is that there are many different types of diagrams and once you put them in place, they can be used to validate the actual code.


Using these tools, you can reverse engineer a code base quite quickly and take in the high level design visually, which is for me the fastest way to understand an application architecture.

It is also quite revealing in that it can show boundary violations between components that cause future extensibility pain. In one case, we identified calls being made from the view directly to the data access layer, bypassing business logic layers. The architect there didn't realise that some of the less experienced developers didn't know they shouldn't do things like that.

Layer and Class diagrams are my favourites. The ability to drag and drop a file from the Solution Explorer in to the diagram makes them a breeze to create.

Once I have diagrams in place, I communicate to the technical leads how to continue to use and create them for regular checks and even in gated check-ins.

A picture really is worth a thousand words.


Tuesday, 11 October 2011

Too General


In the same way that we normalise and denormalise data in a relational database, we have to generalise and specify domain model design in the application.

Developers have a tendency to want to generalise things to an extreme but this often results in losing meaning. Whenever you see something called Object or Entity then it’s gone too far.

A co-worker and I had a discussion about creating a class called LookupItem to represent all reference data. There is no domain meaning in the term LookupItem. It is not a word that our business users would use so it isn’t a word we should use. If you find that commonality then let all your domain model classes inherit from a base class but still have their own class with a meaningful domain object name.

You will end up with lots of small classes but you retained a lot of meaning. Someone who walks in after you and goes to maintain the system will not have to read through the code and see what your named variables to see what a class is used for. It is in the class name.

There is also extensibility inbuilt in to this kind of structure. Often extensibility is required when there is an exception to a rule. Always build your generalisation so they can cope with exceptions to the rules.

Generalise but don’t lose meaning.

Thursday, 22 September 2011

A Thousand Words


When I find myself explaining a concept over and over again to the same or different members of my team, it is a signal that I need to draw a picture.

Often, I draw the picture for a few people before it clicks that I should put it on an A3 piece of paper and stick it on a wall or take a photo and send it around in an email.

In the case above, I was explaining mapping between model classes coming out of different layers of the application. All sorts of words were being used to refer to these objects and it was getting confusing.

This image has given us an explanation of where mapping classes exist; what models coming out of different layers are called; namespaces to be used when creating or referring to mappers and models; and a common language for technical discussion.

To write that in a document would be long and cumbersome.

When you aren't explaining it in code, explain it in pictures.

Acknowledge Me

Apple started a user experience trend many iOSes ago when it accepted Settings changes and did not ask for confirmation. Once the chang...