Monday, April 23, 2012

Convention over implementation with Spring Data

I think that most of us are familiar with the term "Convention over configuration", but just to remember (from wikipedia):
The phrase essentially means a developer only needs to specify unconventional aspects of the application. For example, if there's a class Sale in the model, the corresponding table in the database is called “sales” by default. It is only if one deviates from this convention, such as calling the table “products_sold”, that one needs to write code regarding these names.
When the convention implemented by the tool you are using matches your desired behavior, you enjoy the benefits without having to write configuration files. When your desired behavior deviates from the implemented convention, then you configure your desired behavior.
For example, the maven project structure uses convention - where our source files, test source files and resources should be placed in order to be compiled, tested and packaged automatically. We save a lot of time, and create potentially less bugs, just by following this simple convention. Of course, if we need something special, we can always overwrite it in a way that we need.


But this is only about configuration... I would like to extend it a little bit and talk about convention over implementation (my own term - at least I haven't seen it anywhere else yet ;) ). So that we could write less code to achieve more, do it faster and with higher quality. I am lazy after all...