I spent some time last week working on an Android application, and with my newfound knowledge of functional programming (FP), I was trying to apply FP principles to my Android Activities and Fragments.
Android isn’t really meant for FP, but one thing I found that I could do is to move a lot of my business logic out of the Activities and Fragments and into separate classes, where I could often implement methods as static
functions. The advantage of this is that it forces you to consciously pass variables in and out of those static functions, rather than mutating them as instance variables (think “global” variables) in your Activities and Fragments (which is a common way to handle them).
I don’t have a specific example I can share today, but when I can I’ll update this post to show specifically what I mean. In the meantime, if you try to move some of your logic out of your Activities and Fragments, I think you’ll see what I mean.
This post is sponsored by my new book,
Learn Functional Programming Without Fear.