I've read a lot of books on software design, and more and more I'm wondering if what I learned about separation of concern between business object and serialization makes me more productive.
I'm influenced by Domain Driven Design, so when I design my business classes I don't think about persistance. The only objects who are coupled to my database/web service technology/caching technology are encapsuled behind a repository with a nice domain interface.
To illustrate, for a traditionnal application database<->web service<->RIA, I design my business classes Account and Employee. Then if I want to get accounts from a data source I create a IAccountRepository, and implement methods to query, or add accounts to my data source.
To add caching capability to my application, it's only a matter of creating a proxy class which implements IAccountRepository and wraps the real repository, then inject it in my IOC container.
To implement a database repository, I use an ORM which create classes from my database schema, then I use create a translator to transform database classes to/from business classes, this way my business classes are decoupled from my database schema.
I also create dedicated data contract classes for my web services, then the web service use translators to transform an aggregation of business objects to its data representation from the web service perspective.
When I create my RIA application, again I design its own domain model, but this time the repository implementation use a webservice instead of the database (and again translators).
For WPF developers, I create then my ViewModel and my View.
I used to program like this.
BUT, when my boss comes and says : can you add a field to this form to... blah blah blah I must :
- Update my database
- Update my database translator
- Update my business object
- Update my web service translator (server)
- Update my web service translator (client)
- Update my business object (client)
- Update my view
- For WPF adepts, update my ViewModel
I'm more and more thinking to couple my business object with database access technology and web service technology or serialization technology.
This way I don't need to maintain my translators anymore. For example why not using attributes/annotations of these technologies on the business objects ? Yes it brings some contrains, yes I will need a get/set on my fields, even if I want my property to be readonly, yes my business module will have external dependencies. But I think it will result to less code, and a more maintenable system.
The implementation of my repositories will be trivial, and won't rely on translators.
Although I see advantages to code this way, I always feel guilty to code like this. I feel really guilty about adding a 5 attributes/annotations coupled with my data access technology/web service technology/Serialization technology on my business objects and I feel it's not right.
why my separation of concerns Database/Business objects/Web service, makes me write more code ?
Do you have some alternatives ?