tags:

views:

45

answers:

3

If we had a defined hierarchy in an application. For ex a 3 - tier architecture, how do we restrict subsequent developers from violating the norms?

For ex, in case of MVP (not asp.net MVC) architecture, the presenter should always bind the model and view. This helps in writing proper unit test programs. However, we had instances where people directly imported the model in view and called the functions violating the norms and hence the test cases couldn't be written properly.

Is there a way we can restrict which classes are allowed to inherit from a set of classes? I am looking at various possibilities, including adopting a different design pattern, however a new approach should be worth the code change involved.

A: 

You are wanting to solve a people problem with software? Prepare for a world of pain!

The way to solve the problem is to make sure that you have ways of working with people that you don't end up with those kinds of problems.... Pair Programming / Review. Induction of people when they first come onto the project, etc.

Having said that, you can write tools that analyse the software and look for common problems. But people are pretty creative and can find all sorts of bizarre ways of doing things.

Keith Nicholas
Ohh I am feeling the pain alright!!! I was hoping against hope if there were some sort of framework/tool that could analyze/validate some architectural rulesI guess there is no shortcut to reviews eh?
Srikanth Venugopalan
well, by seperating out the assemblies and making the View entirely independent of the model, so the Presenter provides all the objects the view deals with you could verify that the View doesn't use the Model. But thats more pain than its worth. Mostly.
Keith Nicholas
but that would likely just move your problem somewhere else.... introduce more training on how to work within the architectural style you have
Keith Nicholas
A: 

Just as soon as everything gets locked down according to your satisfaction, new requirements will arrive and you'll have to break through the side of it.

Enforcing such stringency at the programming level with .NET is almost impossible considering a programmer can access all private members through reflection.

Do yourself and favour and schedule regular code reviews, provide education and implement proper training. And, as you said, it will become quickly evident when you can't write unit tests against it.

John K
+1  A: 

I'm afraid this is not possible. We tried to achieve this with the help of attributes and we didn't succeed. You may want to refer to my past post on SO.

The best you can do is keep checking your assemblies with NDepend. NDepend shows you dependancy diagram of assemblies in your project and you can immediately track the violations and take actions reactively.

alt text

this. __curious_geek
@this.__curious_geek: thanks for pointing me to NDepend. I shall check it out.Cool nick btw..
Srikanth Venugopalan