Several weeks ago, I was talking to a programmer and we got into a discussion about the importance of software architecture. I maintained that having a defined architecture is important regardless of the team size, the person I was talking to asserted that architecture wasn’t necessary when there was just one person involved.
But here’s the thing. All software has an architecture. Even the most junior of programmers has an idea of how code should fit together. At issue isn’t really about architecture. It is about having a defined architecture, based on experience and best practices, that will allow the team to develop the software in question as efficiently as possible. Software architecture, at its core, says, “this is how we build software.”
To find the reasons why software architecture matters, it is helpful to think about what happens when there isn’t any defined architecture in place. For the purposes of this article, I’m going to generalize on how architecture impacts teams and where appropriate show why that is also important when your team is just you.
This past week I got into a small discussion about the importance of loosely coupled code. Specifically, I was looking at event handler code that did nothing more than change the size of another element on the screen. But the event handler code was in the controller which in the particular implementation we are using was the event handler portion of our Model in a MVVM architecture. The question becomes does this code belong in the view, or does it belong in the controller?
The question of where code belongs leads eventually to arguments for loosely coupled code. If I put code in my controller that is manipulating the view, then I either need to mock out my view in order to test my controller or I have to have an instance of my view available to test my controller. Having coded enough systems to know that both of those choices are problematic, I opt for placing the view specific code in the view. Another place where you might place this code would be in a View Specific event handler class. But that would only be for the purposes of clean separation. Something we might consider doing if the View were plain HTML. But in our particular case, the view is generated from code, so placing the handlers in that same code seems to be the most appropriate location for it.
But all of this leads to a larger question. Why should your code be loosely coupled at all?
There is a guy I’m working with who is trying to wrap his head around design principles. He’s been watching a lot of PluralSight videos. As he was processing information about Inversion of Control, he asked the natural question I’ve never actually considered before. “Why is it called Inversion of Control? Normally, when you talk about ‘Inversion’ you are talking about reversing something or negating something. That isn’t what we are doing here.”
I’ve had two incidents recently that have shown me how TDD impacts Software Architecture. Both of these are with code I’m working on.
What Software Architecture Might Do
Software architecture might specify how is put together at a very high level. For example, software architecture might specify that we use a three tiered approach or an n-tiered approach. This approach places our view code is at one level, our business rules are at another level, and our data access at yet a third level.