views:

67

answers:

1

I have started using aspects for parameter validation in our development framework. It works nicely, and I enjoy not littering the first half of a public method with validation code.

What I am wondering is if anyone has any recommendations with where in the namespace structure you would place parameter validation? Part of me thinks that since it is top level functionality, it should be in the top-level product namespace - much like the way that System is used in the .NET Framework. I just worry about having the core assembly bloat with more features like this as it goes further down the line.

As it stands right now, I have them in something like:

[Company].[Product].ParameterValidators

In this example, ParameterValidators is the name of the class (aspect) which contains the functionality.

Apart from this, I would be appreciative if anyone had further recommendations for incorporating aspects into an existing codebase in relation to structural placement.

+1  A: 

Right now you are considering partioning using technical criteria, i.e. "Put all validators in a namespace because they are validators". This does not take into account the reason why the validators exist.

My suggestion is to partition by functionality:

  1. All-purpose validators (such as nullity and range-checking) go in an all-purpose namespace.

  2. More-specific validators (such as CustomerValidators) go in more-specific namespaces.

The general idea is that you don't have 1 class that holds all possible validators, you have several classes (in different namespaces) each of which declares validation for a particular reason.

Bryan Watts
Understood, and I should have been more clear. These are top-level validators like "ArgumentInRange" or "ArgumentNotNull". There could be more specific ones driven by specialization.
joseph.ferris
In that case, I would say that all-purpose validation deserves a namespace all its own, as it is a feature area. Specializations should reside with the objects they target.
Bryan Watts
I agree. Marking as the answer. Thanks, Bryan!
joseph.ferris