I had a few discussions about references architectures vs ad hoc design in agile projects. Personally I think both have value, but when you have a standard problem, and a lot of them are standard, I prefer using a standard solution.
The main example in the conversation was if a service layer always is required. A lot of simple web-applications are crud oriented, and especially in such a verbose language as Java, creating a service layer feels like an exercise in futility. I have made my fair share of services that only delegate to doa’s without adding any logic. This means that code needs to be written/tested/maintained, that doesn`t add much value directly. And especially within agile teams, this code just screams ‘remove me’.
But even in crud oriented solutions, having a service layer has value. To give a few arguments:
- you know where security is added. If you want to protect some data, you really don’t want the dao’s to be exposed in the presentation layer. Unluckily this is something I see too often, although they are often tucked away in some sort of request binding logic.
- you know what the transactional setting are. I see a lot of code that is (partially) missing transactional settings. Luckily most databases provide one implicitly, but I don’t find this a professional way of writing software, because you can’t say anything about the consistency of the data: there could be isolation problems like inconsistent views (data that is read from multiple transactions) or lost updates.
So really good arguments have to be provided to convince me from not using a service layer.
If I look on a more higher level, my opinion is that applying reference solutions provides value:
- you know where logic can be found. I guess we all know how irritating it is if you can’t understand a system not because the domain is complex, but the implementation is complex: logic is difficult to find, scattered all over the place and even worse: repeated.
- you know how a system can be changed without needing to know all details of the system. This makes an application, in my opinion, more agile than one with a lot of ad hoc solutions.
- it is easier for new team members to start with the project because they see familiar solutions.
- chance is big that other people have experience with problems of the solution, so there often is knowledge you can fall back on.
So if I see a standard problem, I prefer using a standard solution. Enough books have been written about all kinds of problem domains, for example ‘Patterns of Enterprise Application Architecture’ from Martin Fowler about enterprise applications. But just as important as knowing reference solutions, is knowing when they are not a good match. Using a bad solution is a lot worse than using an ad hoc solution, because the former one always leads to unnecessary complexity.
A deeper concern is that I have the the impression that developers see the Agile methodology as a free card to question all established knowledge. Although I think that questioning knowledge is a good thing, because it helps to remove clutter, ignoring knowledge isn’t. Agile development requires more knowledge about reference solutions because you are designing all the time, and not just in the beginning. If a system isn’t well designed, you are not able to be agile because a system isn’t able to change gracefully.