The Layered Architecture Pattern in Software Architecture

Kayvan Kaseb
Software Development
6 min readMar 27, 2022
The picture is provided by Unsplash

As a matter of fact, software architectural patterns help specify the primary characteristics and behaviors of a software. To select the appropriate architectural pattern that meets your specific business goals, understanding the characteristics, strengths, and weaknesses of architectural patterns is a requisite issue. Even though a number of architectural patterns have been recommended in software development, the layered architecture pattern is well-known due to ease of development and test. This article aims to discuss some main concepts and characteristics of layered architecture pattern in software engineering.

Introduction and Overview

Initially, there are two levels of software design. The level you typically consider while you are developing programs is called detailed design. For instance, there are some issues and questions that could be mentioned in this way: What data structures? What algorithms are you using? How is the database going to be organized? What does the user interface look like? What are the calling sequences? As it is clear, these are all extremely detailed matters that need to be addressed before you can be able to get on with the detailed work of coding. Nevertheless, there is another level of design, which is called style. For example, if you want to build a house, some questions should be answered in this level as follows: One story or multi-story? Which direction do the bedroom windows face? Two bedrooms or three? Open concept floor plan or closed? Probably, these questions emphasis somewhat on details, but they are much more about the style of the house and how you will be using it. This focus on style is what software architecture is all about. In fact, different kinds of programs in various domains will require to consider different architectural styles. You can also call these architectural patterns because they have lots of characteristics of the design patterns.

What do we mean by a software architecture? To me the term architecture conveys a notion of the core elements of the system, the pieces that are difficult to change. A foundation on which the rest must be built.

— Martin Fowler

Software Architecture refers to the fundamental structures of a software system and the discipline of creating such structures and systems. This means Software Architecture serves as a blueprint or template for a system. It offers an abstraction to handle the system complexity, and establishes a communication and coordination mechanism among software components and elements. Software Architecture is about building essential structural choices, which are costly to change once implemented.

Besides, Architectural patterns help specify the fundamental characteristics and behavior of a software. For example, some architectural patterns are basically appropriate for highly scalable software; whereas, some architectural patterns are suitable for applications that are highly agile. So, knowing the characteristics, strengths, and weaknesses of architectural patterns is a requisite issue in order to select the proper one that meets your specific business needs and goals.

Eventually, one of the most well-known software architectural patterns is the layered architecture pattern, which also known as the n-tier architecture pattern. This essay will discuss some main concepts and characteristics of layered architecture pattern in software engineering.

The key concepts of Layered Architecture

The layered architecture is one of the most common patterns used across the software companies since it is easy to develop and also has high capability for testing. Typically, a layered architecture is classified into four distinct layers: presentation, business, persistence, and database; however, the layered architecture pattern does not specify the number and types of layers. Popular frameworks, like Java EE utilized this architecture pattern. For instance, in some situations, the business layer and persistence layer are combined into a single business layer. This means smaller applications might have only three layers in total, in contrast, larger and more complicated business software perhaps consists of five or more layers.

The picture is provided by the Software Architecture Pattern Book

As it is mentioned, there is no predefined number of layers, but the following are ones that software developers see the most often:

  • Presentation layer (User Interface layer): It includes the graphical design of the software, as well as any code to manage user interaction. Only logic specific to the UI should be found within this layer.
  • Business Logic Layer: This layer manages all business logic, validations, and business processes.
  • Data Access Layer: This layer is responsible for interacting with a database, which also known as the persistence layer.
  • Database layer: This layer is the real data store for the software. It consists of the code to access and handle the database behind the software product, as well as the underlying database technology.

Obviously, the main concept of this architecture pattern is splitting the code into various layers. Each layer has a certain responsibility and provides service to a higher layer. One of the powerful characteristics of the layered architecture pattern is the separation of concerns. In short, components within a particular layer must tackle the logic that just only related to that layer. This limited component scope makes it easy to create effective roles and responsibility models into your architecture, and also makes it easy to develop, test, and maintain software in practice.

Another key concept in this architectural pattern is layers of isolation. In general, it means that changes made in one layer of the architecture do not make effect on components in other layers. Thus, each layer is independent of the other layers by having little or no knowledge of the inner workings of other layers in the architecture. Furthermore, each layer in the layered architecture can be classified either closed or open. A closed layer means that as a request transport from layer to layer, the request cannot skip any layer, but must go through the layer instantly below it to get to the next layer in the architecture. On the other hand, an open layered architecture can make use of any of the layers below it. As an example if you allow the presentation layer direct access to the persistence layer, it will make changes and effects on both the business layer and the presentation layer. As a result, it builds a tightly coupled software with a number of dependencies among software components. In a word, this type of architecture becomes very difficult and expensive for changing.

Adding a layer to the architecture

Notwithstanding the fact that closed layers make easier to use the concept of layers of isolation efficiently, open approach could be utilized in some cases. For instance, if there are shared objects within the business layer that includes common functionality for business components, such as data and string utility classes and logging classes. One solution for achieving this goal is adding a new service layer. However, the new service layer has to be specified as open layer because the business layer do not has to be forced to go through the service layer to access the persistence layer.

The picture is provided by the Software Architecture Pattern Book

Understanding the concept of open and closed layers could be useful for defining the appropriate relationship among architecture layers. Also, it provides essential information about different layer access restrictions within the architecture for software developers as well.

Some advantages and disadvantages of using layered architecture pattern

There are some primary benefits of utilizing this pattern in software development as follows:

  1. Easy to develop: Since most software companies develop applications by separating their features by layers, such as presentation, business, and database, this pattern becomes a general choice for most business-application development.
  2. Easy to test: Because components belong to certain layers in the software architecture and layers can focus exclusively on its role, each layer could be mocked easily. This leads to accomplish an easy way of writing a well-organized and testable software.

In contrast, there are some disadvantages in using this pattern in reality. For example, this pattern could not be productive in a constantly changing environment because it is not possible to respond changes immediately. The monolithic nature of most implementations of this pattern is the main reason for time-consuming. In addition, in some cases, the tight coupling can be found in the software architecture in this way. Finally, to perform a business request as it was showed, you have to go through multiple layers of the architecture. Therefore, it is not a productive approach in practice.

In conclusion

Fundamentally, software architectural patterns help specify the core characteristics and behaviors of a software. Although many architectural patterns have been offered in software development, the layered architecture pattern is popular because of ease of development and test. This considered discuss some main concepts and characteristics of layered architecture pattern in software development.

--

--

Kayvan Kaseb
Software Development

Senior Android Developer, Technical Writer, Researcher, Artist, Founder of PURE SOFTWARE YAZILIM LİMİTED ŞİRKETİ https://www.linkedin.com/in/kayvan-kaseb