Aspect-Oriented Programming in OOP world - breaking rules ?

Posted by Maksim Kondratyuk on Stack Overflow See other posts from Stack Overflow or by Maksim Kondratyuk
Published on 2010-06-18T08:25:34Z Indexed on 2010/06/18 8:53 UTC
Read the original article Hit count: 280

Filed under:
|
|

Hi 2 all!

When I worked on asp.net mvc web site project, I investigated different approaches for validation. Some of them were DataAnotation validation and Validation Block. They use attributes for setting up rules for validation. Like this:

[Required]
public string Name {get;set;}

I was confused how this approach combines with SRP (single responsibilty principle) from OOP world. Also I don't like any business logic in business objects, I prefer "poor business objects" model, but when I decorate my business objects with validation attributes for real requirements, they become ugly (Has a lot of attributes / with localization logic and so on).

Idea with attributes realy simple, but in my opinion the validation decoration should be separated from object. I'm not sure is the approach to separate validation rules to xml files or to another objects, maybe it is a solution.

Another bad side of AOP - problems with unit testin such code. When I decorated some controller actions with custom attributes for example to import/export TempData between actions or initialize some required services I can't to write proper unit test for testing this actions.

Do you think that attributes don't break srp or you just disregard this and think that it's simplest , is not worst way ?

P.S. I read some likes articles and discussions and I just want to put things in proper order.

P.P.S. sorry for my "fluent" english :=)

© Stack Overflow or respective owner

Related posts about .NET

Related posts about oop