Sunday, September 13, 2015

Making peace with interfaces

While co-designing a new product, I had to also switch schools of Java.  

I came from an immutable-is-king school where all fields are public finals, constructors are private, and builders are fluent. In this school if you have a task you break it up into necessary data transfer objects. Any gateway communication like sql or soap is hand crafted and hidden inside methods of your data model.

I'm switching to a functional grouping of modules. In this way interfaces are designed while tests are created. Your tasks first get APIs, then get necessary data accessors. Public final fields are from this view too restrictive in data location.

For example in the first way a documentID is stored and a method to send a document then is in charge of using it.

In the second way, a document accessor interface is defined and an implementation is passed when any user needs a document, allowing any module to locate documents reliably and without duplication.

It makes pragmatic thinking more difficult while not limiting it. For this cost you get consistent reliable implementation visibility control.

More business and less programming if you ask me.

No comments:

Post a Comment