The last couple of days were full of excitement in the Android world as Google I/O took place. In no surprise, some of the rumours came true and Android M was announced (with a possibility to download the preview as last year), which comes with a bunch of new APIs.

One of the new API that caught my eye is the Data Binding Library. In short, it lets you bind data directly into your layouts by having a POJO - variable declaration pair. Let's take the example from the official documentation:

So far so good, nothing really complicated or hard to comprehend. In a way, this removes a bit of boilerplate code (not having to findViewById() or setText()). My first impression was that this is the aim of this API.

Things start to take a slippery slope

Going forward with reading the documentation, you can see that you can do a lot more with Data Binding than to simply remove the need of findViewById() and attach simple data to your views.

You can actually import java classes in your layouts and use them directly in place:

And you can do a lot more with having Observable Fields, Observable Collections or custom bindings. All of these can be found in the official documentation.

This is more than binding simple data to your views and avoiding the boilerplate code. To me, this is actually mixing business logic in your UI layouts. Your views should be as dumb as possible, adhering to the Single Responsibility Principle with the only responsibility to show data. This could lead to a complicated, cluttered and unclean codebase.

We've seen some of the examples of the Data Binding API. I'm sure that this API was created in order to ease the developers' work and avoid boilerplate, but one can overuse it and accidentally create chaos in his code. Mixing Java in your view code has never been a good idea. Does JSP ring a bell?

I'm looking forward to seeing the different use cases in which developers will make use of the Data Binding API. How would you use it?