Back to table of contents

Credit: Creative Commons 0

Architecture

Andrew J. Ko

Once you have a sense of what your design must do (in the form of requirements or other less formal specifications), the next big problem is one of organization. How will you order all of the different data, algorithms, and control implied by your requirements? With a small program of a few hundred lines, you can get away without much organization, but as programs scale, they quickly become impossible to manage alone, let alone with multiple developers. Much of this challenge occurs because requirements change, and every time they do, code has to change to accommodate. The more code there is and the more entangled it is, the harder it is to change and more likely you are to break things.

This is where architecture comes in. Architecture is a way of organizing code, just like building architecture is a way of organizing space. The idea of software architecture has at its foundation a principle of information hiding: the less a part of a program knows about other parts of a program, the easier it is to change. The most popular information hiding strategy is encapsulation: this is the idea of designing self-contained abstractions with well-defined interfaces that separate different concerns in a program. Programming languages offer encapsulation support through things like functions and classes, which encapsulate data and functionality together. Another programming language encapsulation method is scoping, which hides variables and other names from other parts of program outside a scope. All of these strategies attempt to encourage developers to maximize information hiding and separation of concerns. If you get your encapsulation right, you should be able to easily make changes to a program's behavior without having to change everything about it's implementation.

When encapsulation strategies fail, one can end up with what some affectionately call a "ball of mud" architecture or "spaghetti code". A more precise concept is cross-cutting concerns, which are things like features and functionality that span multiple different components of a system, or even an entire system. There is some evidence that cross-cutting concerns can lead to difficulties in program comprehension and long-term design degradation (Walker et al. 2012), all of which reduce productivity and increase the risk of defects. As long-lived systems get harder to change, they can take on technical debt, which is the degree to which an implementation is out of sync with a team's understanding of what a product is intended to be. Many developers view such debt as emerging from primarily from poor architectural decisions (Ernst et al. 2015). Over time, this debt can further result in organizational challenges (Khadka et al. 2014), making change even more difficult.

The preventative solution to this problems is to try to design architecture up front, mitigating the various risks that come from cross-cutting concerns (defects, low modifiability, etc.) (Fairbanks 2010). A popular method in the 1990's was the Unified Modeling Language (UML), which was a series of notations for expressing the architectural design of a system before implementing it. Recent studies show that UML generally not used and generally not universal (Petre 2013). More recent developers have investigated ideas of architectural styles, which are patterns of interactions and information exchange between encapsulated components. Some common architectural styles include:

Architectural styles come in all shapes and sizes. Some are smaller design patterns of information sharing (Beck et al. 2006), whereas others are ubiquitous but specialized patterns such as the architectures required to support undo and cancel in user interfaces (Bass et al. 2004).

One fundamental unit of which an architecture is composed is a component. This is basically a word that refers to any abstraction—any code, really—that attempts to encapsulate some well defined functionality or behavior separate from other functionality and behavior. Components have interfaces that decide how it can communicate with other components. It might be a class, a data structure, a set of functions, a library, or even something like a web service. All of these are abstractions that encapsulate interrelated computation and state. The second fundamental unit of architecture is connectors. Connectors are abstractions (code) that transmit information between components. They're brokers that connect components, but do not necessarily have meaningful behaviors or states of their own. Connectors can be things like function calls, web service API calls, events, requests, and so on.

Even with carefully selected architectures, systems can still be difficult to put together, leading to architectural mismatch (Garlan et al. 1995). When mismatch occurs, connecting two styles can require dramatic amounts of code to connect, imposing significant risk of defects and cost of maintenance. One common example of mismatches occurs with the ubiquitous use of database schemas with client/server web-applications. A single change in a database schema can often result in dramatic changes in an application, as every line of code that uses that part of the scheme either directly or indirectly must be updated (Qiu et al. 2013). This kind of mismatch occurs because the component that manages data (the database) and the component that renders data (the user interface) is highly "coupled" with the database schema: the user interface needs to know a lot about the data, its meaning, and its structure in order to render it meaningfully.

The most common approach to dealing with both architectural mismatch and the changing of requirements over time is refactoring, which means changing the architecture of an implementation without changing its behavior. Refactoring is something most developers do as part of changing a system (Murphy-Hill et al 2009, Silva et al. 2016). Refactoring code to eliminate mismatch and technical debt can simplify change in the future, saving time (Ng et al. 2006) and prevent future defects (Kim et al. 2012).

Research on the actual activity of software architecture is actually somewhat sparse. One of the more recent syntheses of this work is Petre et al.'s book, Software Design Decoded (Petre et al. 2016), which distills many of the practices and skills of software design into a set of succinct ideas. For example, the book states, "Every design problem has multiple, if not infinite, ways of solving it. Experts strongly prefer simpler solutions over complex ones, for they know that such solutions are easier to understand and change in the future." These ideas, while powerful in their conciseness, are also grounded in substantial research on how software architects think and work.

Next chapter: Specifications

Further reading

Len Bass, Bonnie E. John. 2003. Linking usability to software architecture patterns through general scenarios. Journal of Systems and Software, Volume 66, Issue 3, Pages 187-197.

Kent Beck, Ron Crocker, Gerard Meszaros, John Vlissides, James O. Coplien, Lutz Dominick, and Frances Paulisch. 1996. Industrial experience with design patterns. In Proceedings of the 18th international conference on Software engineering (ICSE '96). IEEE Computer Society, Washington, DC, USA, 103-114.

Jürgen Cito, Philipp Leitner, Thomas Fritz, and Harald C. Gall. 2015. The making of cloud applications: an empirical study on software development for the cloud. In Proceedings of the 2015 10th Joint Meeting on Foundations of Software Engineering (ESEC/FSE 2015). ACM, New York, NY, USA, 393-403.

Neil A. Ernst, Stephany Bellomo, Ipek Ozkaya, Robert L. Nord, and Ian Gorton. 2015. Measure it? Manage it? Ignore it? Software practitioners and technical debt. In Proceedings of the 2015 10th Joint Meeting on Foundations of Software Engineering (ESEC/FSE 2015). ACM, New York, NY, USA, 50-60.

Fairbanks, G. (2010). Just enough software architecture: a risk-driven approach. Marshall & Brainerd.

Garlan, D., Allen, R., & Ockerbloom, J. (1995). Architectural mismatch or why it's hard to build systems out of existing parts. In Proceedings of the 17th international conference on Software engineering (pp. 179-185).

Ravi Khadka, Belfrit V. Batlajery, Amir M. Saeidi, Slinger Jansen, and Jurriaan Hage. 2014. How do professionals perceive legacy systems and software modernization? In Proceedings of the 36th International Conference on Software Engineering (ICSE 2014). ACM, New York, NY, USA, 36-47.

Miryung Kim, Thomas Zimmermann, and Nachiappan Nagappan. 2012. A field study of refactoring challenges and benefits. In Proceedings of the ACM SIGSOFT 20th International Symposium on the Foundations of Software Engineering (FSE '12). ACM, New York, NY, USA, , Article 50 , 11 pages.

Emerson Murphy-Hill, Chris Parnin, and Andrew P. Black. 2009. How we refactor, and how we know it. In Proceedings of the 31st International Conference on Software Engineering (ICSE '09). IEEE Computer Society, Washington, DC, USA, 287-297.

T. H. Ng, S. C. Cheung, W. K. Chan, and Y. T. Yu. 2006. Work experience versus refactoring to design patterns: a controlled experiment. In Proceedings of the 14th ACM SIGSOFT international symposium on Foundations of software engineering (SIGSOFT '06/FSE-14). ACM, New York, NY, USA, 12-22.

Marian Petre. 2013. UML in practice. In Proceedings of the 2013 International Conference on Software Engineering (ICSE '13). IEEE Press, Piscataway, NJ, USA, 722-731.

Petre, M., van der Hoek, A., & Quach, Y. (2016). Software Design Decoded: 66 Ways Experts Think. MIT Press.

Danilo Silva, Nikolaos Tsantalis, and Marco Tulio Valente. 2016. Why we refactor? Confessions of GitHub contributors. In Proceedings of the 2016 24th ACM SIGSOFT International Symposium on Foundations of Software Engineering (FSE 2016). ACM, New York, NY, USA, 858-870.

Dong Qiu, Bixin Li, and Zhendong Su. 2013. An empirical analysis of the co-evolution of schema and code in database applications. In Proceedings of the 2013 9th Joint Meeting on Foundations of Software Engineering (ESEC/FSE 2013). ACM, New York, NY, USA, 125-135.

Robert J. Walker, Shreya Rawal, and Jonathan Sillito. 2012. Do crosscutting concerns cause modularity problems? In Proceedings of the ACM SIGSOFT 20th International Symposium on the Foundations of Software Engineering (FSE '12). ACM, New York, NY, USA, , Article 49 , 11 pages.

Podcasts

Software Engineering Daily, React JS with Sebastian Marbage and Christopher Chedeua