From the course: Software Architecture: Patterns for Developers (2020)

What are software architecture patterns?

- [Instructor] It's important that we have a shared understanding of the term software architecture patterns. So let's try to come up with a definition. A pattern in software is basically a solution to a common problem. If you're facing this or a similar problem, you might be able to solve it by applying the solution. The pattern then defines components and the interactions between them. We can compare it to writing. If you want to bring across a message, you can just start writing away wildly saying whatever comes up but that wouldn't help in communicating your message. You could do better by structuring your text with an introduction, body, and conclusion. Or, for example, a lot of fantasy books follow what's called a three-act structure. First, the characters are introduced and there is a disaster which forces them to go on an adventure. Then there is the actual adventure where the characters work towards a goal. And finally, there is the big finale in which they are usually victorious. There are many other patterns, but the point is that they give both the author and the reader a structure that they can follow easily. Software patterns come in all shapes and sizes. What most developers think about when they hear the term software patterns are things like the repository pattern, the singleton pattern, the builder pattern, or the factory pattern and there are many more. These are patterns that define how to write and interact with certain classes. The repository pattern, for example, shows us how we can abstract the way implementation details on how to retrieve data from a database. A piece of our application would call a repository class, which contains the logic to build and send a SQL query to the database. It also contains the logic to translate the database response to the format that the application code will understand. Let's look at another example. To parse a string into an integer in C#, you can use the following code: int x equals int.parse three. This will return an integer. But what happens if we use a string that doesn't represent the number? Like int y equals int.parse hello. This will throw an exception. If we're not sure about the input, we can use the TryParse method like this. Int z equals zero and then if int.TryParse input, out z. This function will not throw an exception if it can't parse the input. This is sometimes called the TryParse pattern. You provide an API that contains a parse and the TryParse method. The convention then states that the parse method can't throw an exception if it encounters something that it can't parse. But the TryParse method shouldn't throw an exception. It will return false if it can't parse the input. And if it can, it returns true and sets the value of the out parameter. We call this a pattern because it features on other .net classes and structs as well. This makes it recognizable for many .net developers. So we can encounter patterns on all levels in software. When we talk about software architecture patterns, we're looking at how applications are structured on a higher level. The line isn't always clear, but we're looking beyond the single class level to use an object-oriented term. We're not focusing on how to write and interact with a single class. Software architecture patterns will show us how we can structure and interact with multiple classes in our application. We could even go up a level and identify patterns that show us how to organize multiple independent applications, regardless of how those are structured internally.

Contents