Single Responsibility vs. Ease of Use

posted on 08/11/07 at 12:04:11 am by Joel Ross

Erik Lane recently posted about the contradiction between Single Responsibility Principle and Encapsulation. Well, it's not a true contradiction.?It?gets introduced during implementation. He asks how much should an object know about itself - should it know how to update itself, or do we really want just Data Transfer Objects.

If you break down what Erik's suggesting, it makes total sense, and I don't think many people would argue against it. Basically, he's saying let's take our DTOs and give them a little more knowledge about themselves - make them true objects - and pull the level of abstraction up one layer. It also lessens the amount of knowledge people using your objects have to know about your objects.?

I typically like to have objects that know a lot about themselves. It makes consuming the API simpler and to me, it just makes more sense, regardless of the "correctness" of it all.

Categories: Development