Tuesday, May 31, 2011

Partitioning code in namespaces

Partitioning code in namespaces will always fail in a layered architecture. Fail in a sense that you can't get a perfect partitioning!
In layered architectures we have two (and possibly more) reasonable category systems to group our code. The first is to group it by a layer fashion, that means that your UserService and your BillingService would both be in the My.Startup.Services namespace with all the pros and cons. Second system is to group classes in namespaces by their functional responsibility which means that UserService, UserRepository and User can be found in the My.Startup.Users namespace.

You can't get both in OO languages. We would need a taxonomy instead of a category system for a "perfect partition" but I would not want to work with that :)

In my daily work I avoid partitioning in a layered fashion because it's terrible to navigate, terrible to pull out functional components in reusable libraries and from design view the classes in a namespace have almost no cohesion.

0 comments:

Post a Comment