Black and blue background

Three-tier architecture is a well-established software application architecture that organizes applications into three logical and physical computing tiers: the presentation tier, or user interface; the application tier, where data is processed; and the data tier, where application data is stored and managed.

The chief benefit of three-tier architecture is that because each tier runs on its own infrastructure, each tier can be developed simultaneously by a separate development team. And can be updated or scaled as needed without impacting the other tiers.

For decades three-tier architecture was the prevailing architecture for client-server applications. Today, most three-tier applications are targets for modernization that uses cloud-native technologies such as containers and microservices and for migration to the cloud.

Connect and integrate your systems to prepare your infrastructure for AI.

Register for the guide on app modernization

Presentation tier

The presentation tier is the user interface and communication layer of the application, where the end user interacts with the application. Its main purpose is to display information to and collect information from the user. This top-level tier can run on a web browser, as desktop application, or a graphical user interface (GUI), for example. Web presentation tiers are developed by using HTML, CSS, and JavaScript. Desktop applications can be written in various languages depending on the platform.

Application tier

The application tier, also known as the logic tier or middle tier, is the heart of the application. In this tier, information that is collected in the presentation tier is processed - sometimes against other information in the data tier - using business logic, a specific set of business rules. The application tier can also add, delete, or modify data in the data tier. 

The application tier is typically developed by using Python, Java, Perl, PHP or Ruby, and communicates with the data tier by using  API  calls. 

The data tier, sometimes called database tier, data access tier or back-end, is where the information that is processed by the application is stored and managed. This can be a  relational database management system  such as  PostgreSQL , MySQL, MariaDB, Oracle, Db2, Informix or Microsoft SQL Server, or in a  NoSQL  Database server such as Cassandra,  CouchDB , or  MongoDB . 

In a three-tier application, all communication goes through the application tier. The presentation tier and the data tier cannot communicate directly with one another.

Tier versus layer

In discussions of three-tier architecture,  layer  is often used interchangeably – and mistakenly – for  tier , as in 'presentation layer' or 'business logic layer'. 

They aren't the same. A 'layer' refers to a functional division of the software, but a 'tier' refers to a functional division of the software that runs on infrastructure separate from the other divisions. The Contacts app on your phone, for example, is a  three - layer  application, but a  single-tier  application, because all three layers run on your phone.

The difference is important because layers can't offer the same benefits as tiers.

Again, the chief benefit of three-tier architecture is its logical and physical separation of functionality. Each tier can run on a separate operating system and server platform - for example, web server, application server, database server - that best fits its functional requirements. And each tier runs on at least one dedicated server hardware or virtual server, so the services of each tier can be customized and optimized without impacting the other tiers. 

Other benefits (compared to single- or two-tier architecture) include:

  • Faster development : Because each tier can be developed simultaneously by different teams, an organization can bring the application to market faster. And programmers can use the latest and best languages and tools for each tier.
  • Improved scalability : Any tier can be scaled independently of the others as needed.
  • Improved reliability : An outage in one tier is less likely to impact the availability or performance of the other tiers.
  • Improved security : Because the presentation tier and data tier can't communicate directly, a well-designed application tier can function as an internal firewall, preventing SQL injections and other malicious exploits.

In web development, the tiers have different names but perform similar functions:

  • The web server  is the presentation tier and provides the user interface. This is usually a web page or website, such as an ecommerce site where the user adds products to the shopping cart, adds payment details or creates an account. The content can be static or dynamic, and is developed using HTML, CSS, and JavaScript.
  • The application server  corresponds to the middle tier, housing the business logic that is used to process user inputs. To continue the ecommerce example, this is the tier that queries the inventory database to return product availability, or adds details to a customer's profile. This layer often developed using Python, Ruby, or PHP and runs a framework such as Django, Rails, Symphony, or ASP.NET.
  • The database server  is the data or backend tier of a web application. It runs on database management software, such as MySQL, Oracle, DB2, or PostgreSQL.

While three-tier architecture is easily the most widely adopted multitier application architecture, there are others that you might encounter in your work or your research.

Two-tier architecture 

Two-tier architecture is the original client-server architecture, consisting of a presentation tier and a data tier; the business logic lives in the presentation tier, the data tier or both. In two-tier architecture the presentation tier - and therefore the end user - has direct access to the data tier, and the business logic is often limited. A simple contact management application, where users can enter and retrieve contact data, is an example of a two-tier application. 

N-tier architecture

N-tier architecture - also called or multitier architecture - refers to  any  application architecture with more than one tier. But applications with more than three layers are rare because extra layers offer few benefits and can make the application slower, harder to manage and more expensive to run. As a result, n-tier architecture and multitier architecture are usually synonyms for three-tier architecture.

Move to cloud faster with IBM Cloud Pak solutions running on Red Hat OpenShift software—integrated, open, containerized solutions certified by IBM®.

Seamlessly modernize your VMware workloads and applications with IBM Cloud.

Modernize, build new apps, reduce costs, and maximize ROI.

IBM Consulting® application modernization services, which are powered by IBM Consulting Cloud Accelerator, offers skills, methods, tools, and initiatives that help determine the right strategy based on your portfolio. To modernize and containerize legacy system applications and accelerate the time-to-value of hybrid cloud environments. 

Discover what application modernization is, the common benefits and challenges, and how to get started.

Learn about how relational databases work and how they compare to other data storage options.

Explore cloud native applications and how they drive innovation and speed within your enterprise.

Modernize your legacy three-tier applications on your journey to cloud. Whether you need assistance with strategy, processes, or capabilities—or want full-service attention—IBM can help. Start using containerized middleware that can run in any cloud—all bundled in IBM Cloud Paks.

  • SimilarContent
  • Netpeak Software
  • Article Forge
  • Jasper AI Copywriter
  • Dreamstime.com
  • Renderforest
  • Office Timeline
  • Smashinglogo
  • GetResponse
  • Klenty – Sales Engagement Tool
  • Benchmark Email
  • PromoRepublic
  • Constant Contact
  • FindThatLead
  • EmailOctopus
  • SmarterQueue
  • Iconosquare
  • Social Champ
  • SocialOomph
  • Social Searcher
  • BrandMentions
  • ProWorkflow
  • Alerter System
  • Bettermode Review
  • AutoFxPro.com
  • Blubrry Podcasting
  • ContentStudio
  • Influencer Marketing
  • Growth Strategies
  • Entrepreneurs
  • Inspiration
  • Media Mister
  • Getty Images
  • Hire Writers
  • AMZ Watcher
  • Sitechecker Pro
  • Gravity Forms
  • Supermetrics

What is Presentation Logic? Complete Guide

Logic is the foundation of all web applications . It is the backbone of all business applications, from websites to mobile apps . In addition to being a crucial component of a web application, presentation logic is also crucial for the development of interactive experiences. Essentially, presentation logic is a way to present information to users in the most efficient manner possible. Using the proper presentation logic, an application can improve its user experience and improve sales results.

A good example of presentation logic is found in game programming. Games use computer software that takes input from a game controller and forces characters on the screen to perform tasks. Modern computer applications are designed to react to human movement through special cameras or infrared devices. This allows them to build a virtual environment that makes the user feel as though they are actually inside the gaming system. In fact, a game program’s presentation logic may be the most complex part of its code.

While business logic consists of the rules of a company, presentation logic refers to how the details of an application are displayed. Both are important but must be considered separately. A business application can’t operate without either. It must adhere to both of these standards to keep users happy. In addition, it should also be easy to use. There are many types of presentation logic. Some are easier to use than others, but they are both important in any application.

Presentation logic is a concept in software development . It describes how the business objects are displayed to the user. This can include displaying information through pop-up screens or drop-down menus. A presentation layer can be built using prototyping tools, and then tested in a user acceptance testing environment. When it’s complete, it will be able to validate the data and business rules of the application. Then it can be used for user acceptance testing.

The two most common types of presentation logic are business logic and presentation logic. The latter is the most general type of presentation logic. It outlines the steps necessary to complete an action. Similarly, presentation logically explains how the business objects are presented to the user. When it is properly implemented, it will ensure that users retain the information. It will also ensure that the audience is able to understand the content of the application.

In simple terms , presentation logic is the processing required to create a print-out. It is also called business logic. It is an important part of an application, as it can define the business rules and actions that should be performed. It is also known as user interface. This layer is the foundation of the entire system. It’s where the business rules are implemented. Usually, presentation logic is implemented in the client side of a web-based application .

Presentation logic is the core of the application. The business logic layer provides a foundation for the user to interact with the application. It also contains all the business rules for the server. By contrast, presentation logic is the underlying code that determines how the data is presented. In contrast to business rules, presentation logic is the “rules” part. Instead of business rules, the logic layer implements the data stored on the server.

In Java, presentation logic is the logical presentation of ideas in a database. While business logic is the underlying code of an application, presentation logic is the logic for the data. And presentation logic is the core of an application. JSTL is a logical way to express business rules. This means that the data in an object is organized in the right way and a specific format must be used for it to be effective .

The presentation logic in an application is the logical layer for ideas. It is different from business logic. For instance, the presentation layer presents the objects that a user sees. The business logic is the logical way to apply the business rules. In this case, the presentation logic focuses on the data. It has a UI, and it must not be confusing. And application logic is the core of the system.

Presentation Layer

The presentation layer is a component of the software architecture that handles the user interface (UI) of an application. It is the layer that the end-users interact with, and its primary function is to present information to the user in a way that is understandable and easy to use.

The Presentation Layer is responsible for handling the presentation logic, which defines how the information will be presented to the user. It also handles user input validation and formatting of output data. The layer communicates with the application layer and the data layer to obtain the necessary information and to perform necessary actions.

The Presentation Layer consists of several components, including the user interface components, such as buttons, text boxes, and menus. It also includes the visual design components, such as themes and templates, that define the look and feel of the application. Additionally, it may include the animation and multimedia components, such as images, videos, and audio files.

The Presentation Layer has an essential role in software architecture. It is the layer that creates the first impression of the application for the users, and it affects the usability and user experience of the software. A well-designed presentation layer can make a significant difference in the success of the application.

The Presentation Layer is often implemented using web technologies, such as HTML, CSS , and JavaScript, for web-based applications, or platform-specific technologies, such as JavaFX or WPF, for desktop applications. The choice of technology depends on the requirements of the application and the target platform.

In conclusion, the Presentation Layer is a crucial component of software architecture that handles the user interface of an application. It is responsible for presenting information to the user, validating user input, and formatting output data. The presentation layer components include user interface components, visual design components, and animation and multimedia components. The Presentation Layer is implemented using web or platform-specific technologies, depending on the requirements of the application.

Presentation Logic

Presentation Logic is the part of software logic responsible for determining how the user interface components of an application should behave and interact with each other. It defines how the user interface will be presented to the user and how it will respond to user input.

Presentation Logic is closely related to the Presentation Layer, as it is responsible for implementing the behavior of the user interface components in that layer. It encapsulates the behavior of each component and determines how it should respond to user interactions, such as mouse clicks, keyboard input, or touch events.

The Presentation Logic is responsible for the following tasks:

  • Validating user input: it ensures that the user input is in the correct format and within the expected range of values.
  • Formatting output data: it formats the data to be displayed to the user in a way that is easy to read and understand.
  • Managing user interface state: it maintains the state of the user interface components, such as their visibility, enabled/disabled status, and data values.
  • Implementing user interface flow: it defines the navigation between different screens or pages of the application and manages the flow of the user interface.

Examples of Presentation Logic include:

  • Enabling and disabling buttons based on user input: For example, disabling a “submit” button until all required fields in a form have been completed.
  • Formatting data for display: For example, formatting a date to display as “DD/MM/YYYY” or “MM/DD/YYYY” based on user preferences.
  • Implementing conditional logic: For example, showing or hiding specific user interface components based on user input or application state.
  • Managing user authentication: For example, requiring users to log in before accessing certain features of the application.

The Presentation Logic should be designed to be reusable, maintainable, and testable. It should be separated from the business logic and data access logic to ensure that each layer can be developed independently.

Features of Presentation Logic

Presentation Logic has several features that are essential to ensure its effectiveness in software development. These features include separation of concerns, reusability, testability, and maintainability.

Separation of Concerns

Presentation Logic should be separated from other layers of the application to allow for clear division of responsibilities. Separation of concerns helps to reduce complexity, increase modularity, and promote code reuse. By separating Presentation Logic from business logic and data access logic, it becomes easier to maintain and test each layer independently.

Reusability

Presentation Logic should be designed to be reusable across different parts of the application. It allows for code reduction, faster development, and a consistent user experience. Reusable Presentation Logic components, such as form validation or navigation, can be shared across different screens or pages of the application, resulting in code optimization and reducing the time and effort required for development.

Testability

Presentation Logic should be designed to be easily testable to ensure its reliability and quality. Testability allows for quick and efficient debugging and helps to identify issues early in the development process. The Presentation Logic should be separated from the user interface components, allowing for the use of automated testing tools and frameworks to test its functionality.

Maintainability

Presentation Logic should be designed to be easy to maintain, update, and modify. It should be well-structured, with clear and concise code that is easy to understand. The Presentation Logic should follow coding best practices, such as code commenting, documentation, and consistent coding style. Good coding practices can help prevent errors, reduce bugs, and make it easier for other developers to work on the codebase.

In conclusion, Presentation Logic is a critical component of software development that determines how the user interface components of an application behave and interact with each other. The features of Presentation Logic include separation of concerns, reusability, testability, and maintainability. Separation of concerns allows for clear division of responsibilities, reusability enables code reduction and consistency, testability ensures reliability and quality, and maintainability promotes easy updates, modifications, and debugging. Developers should aim to implement these features in their Presentation Logic to create efficient and reliable software applications.

Benefits of Presentation Logic

Presentation Logic plays a crucial role in software development and provides several benefits to developers and end-users. These benefits include increased user experience, improved performance, reduced development time, and easier maintenance.

Increased User Experience

Presentation Logic determines how the user interface components are presented to the user, how they interact with each other, and how they respond to user input. By designing a clean and intuitive user interface with well-defined Presentation Logic, developers can improve the user experience of their application. Users are more likely to enjoy using an application that is easy to navigate, provides clear and concise feedback, and responds to their input quickly.

Improved Performance

Presentation Logic can significantly impact the performance of an application. By separating the user interface components from the business logic and data access logic, developers can optimize the performance of each layer independently. Well-designed Presentation Logic ensures that the user interface components are only updated when necessary, reducing the load on the application and improving overall performance.

Reduced Development Time

Presentation Logic can significantly reduce the development time required for an application. By using reusable components, developers can quickly develop and integrate new features into their applications. By separating Presentation Logic from business logic and data access logic, developers can work on each layer independently, allowing for parallel development and faster iteration.

Easier Maintenance

Presentation Logic can make it easier to maintain and update an application. By separating the user interface components from the business logic and data access logic, developers can easily modify or update the Presentation Logic without affecting other parts of the application. Well-structured Presentation Logic also promotes easy debugging, testing, and maintenance.

In conclusion, Presentation Logic provides several benefits to developers and end-users, including increased user experience, improved performance, reduced development time, and easier maintenance. Developers should aim to design well-structured Presentation Logic that is reusable, maintainable, and testable to create efficient and reliable software applications. By leveraging the benefits of Presentation Logic, developers can create user-friendly applications that are easy to maintain, update, and improve over time.

Best Practices for Implementing Presentation Logic

To implement Presentation Logic effectively, developers should follow certain best practices to ensure that the code is efficient, maintainable, and scalable. The following are some of the best practices for implementing Presentation Logic.

Follow the Separation of Concerns Principle

One of the most important best practices for implementing Presentation Logic is to follow the Separation of Concerns principle. This principle involves separating different concerns of an application into distinct modules or layers. By separating Presentation Logic from business logic and data access logic, developers can reduce the complexity of the codebase and make it easier to maintain and modify.

Use a Design Pattern

Using a design pattern such as Model-View-Controller (MVC) or Model-View-ViewModel (MVVM) can make it easier to implement Presentation Logic. These patterns help to separate the user interface, data, and business logic of an application into different modules, allowing for easier maintenance and testing.

Use Data Binding

Data binding is a technique that allows developers to bind data properties directly to user interface elements. This technique makes it easier to update the user interface elements when the underlying data changes. Using data binding can significantly reduce the amount of code required to implement Presentation Logic.

Use Reusable Components

Developers should aim to create reusable components for Presentation Logic wherever possible. This approach allows developers to use the same components across multiple screens or pages, reducing the amount of code required and promoting consistency in the user interface. Reusable components also make it easier to modify or update the Presentation Logic in the future.

Follow Coding Best Practices

Developers should follow coding best practices such as using consistent naming conventions, documenting the code, and avoiding duplicate code. These practices can help to improve the readability and maintainability of the codebase and reduce the likelihood of errors and bugs.

Use Automated Testing

Automated testing is an essential practice for implementing Presentation Logic effectively. Developers should write automated tests for their Presentation Logic to ensure that it is functioning as expected and to catch bugs and errors early in the development process. Automated testing can also help to reduce the amount of time and effort required for manual testing.

Frequently asked questions

What is presentation logic vs application logic.

Presentation logic and application logic are both important components of a software system, but they serve different purposes.

Presentation logic refers to the code that controls the user interface of an application. This includes the layout, formatting, and behavior of the various elements that the user interacts with, such as buttons, text boxes, and menus. The presentation logic is responsible for ensuring that the application’s user interface is visually appealing, intuitive, and easy to use.

Application logic, on the other hand, refers to the code that controls the underlying functionality of the application. This includes the algorithms and business logic that handle data processing, calculations, and other tasks that are essential to the application’s core functionality. The application logic is responsible for ensuring that the application functions correctly and efficiently.

To summarize, presentation logic is concerned with how the application looks and behaves, while application logic is concerned with what the application does. Both are important components of a software system, and they work together to create a seamless user experience.

What is the presentation logic components?

The presentation logic components typically include the following:

  • User interface design: This component includes the layout and appearance of the user interface elements, such as buttons, menus, forms, and screens. The user interface design should be visually appealing and easy to use.
  • Input validation: This component includes the code that checks the user input to ensure that it is valid and meets the required format and content. Input validation is important for data integrity and security.
  • Event handling: This component includes the code that responds to user actions, such as clicking a button or entering data into a form. Event handling is essential for enabling user interactions and for triggering the application logic.
  • Navigation: This component includes the code that controls how users navigate through the application. Navigation should be intuitive and consistent throughout the application.
  • Error handling: This component includes the code that detects and handles errors that occur during user interactions. Error handling should provide helpful feedback to the user and prevent the application from crashing.
  • User preferences and settings: This component includes the code that allows users to customize the application to their preferences, such as changing the language, font size, or color scheme.

These presentation logic components work together to create a user-friendly and visually appealing interface that enables users to interact with the application in a seamless and intuitive manner.

What is the importance of presentation logic?

The presentation logic of an application is important for several reasons:

  • User experience: The presentation logic is responsible for creating a user-friendly and visually appealing interface that enables users to interact with the application in an intuitive and seamless manner. A well-designed user interface can enhance the user experience and increase user satisfaction.
  • Usability: The presentation logic is responsible for ensuring that the user interface is easy to use and navigate. A well-designed user interface can improve the usability of an application, making it easier for users to achieve their goals.
  • Branding and identity: The presentation logic can also contribute to the branding and identity of an application. A visually appealing and consistent user interface can help to establish the brand identity and differentiate the application from competitors.
  • Accessibility: The presentation logic is responsible for ensuring that the user interface is accessible to all users, including those with disabilities. A well-designed user interface can enhance accessibility and ensure that all users can use the application effectively.
  • Flexibility: The presentation logic can provide flexibility and customization options for users, such as allowing them to adjust the font size, color scheme, or language. This can improve user satisfaction and engagement.
  • Overall, the presentation logic is important for creating a positive user experience, enhancing usability, establishing brand identity, improving accessibility, and providing flexibility and customization options for users.

Presentation Logic is an essential component of modern software development. It refers to the logic that determines how the user interface components of an application are presented to the user, how they interact with each other, and how they respond to user input. By designing a clean and intuitive user interface with well-defined Presentation Logic, developers can improve the user experience of their application.

In this article, we have explored the concept of Presentation Logic in detail, discussing its definition, components, and features. We have also outlined the benefits of implementing Presentation Logic, such as increased user experience, improved performance, reduced development time, and easier maintenance. Finally, we have provided some best practices for implementing Presentation Logic effectively, such as following the Separation of Concerns principle, using a design pattern, using data binding, creating reusable components, following coding best practices, and using automated testing.

In conclusion, Presentation Logic is a critical aspect of software development that can significantly impact the user experience, performance, and maintainability of an application. By implementing Presentation Logic effectively and following best practices, developers can create efficient, scalable, and user-friendly applications that meet the needs of their users.

Leave a Reply Cancel reply

You must be logged in to post a comment.

Related Posts

Exploring the design and applications of conductive inks in printed electronics

Exploring the design and applications of conductive inks in printed electronics

Expanding Horizons: The Strategic Advantage of a German Virtual Number

Expanding Horizons: The Strategic Advantage of a German Virtual Number

Navigating Cloud: A Comprehensive Guide to Successful Azure Migration

Navigating Cloud: A Comprehensive Guide to Successful Azure Migration

Tips and Tricks for Designing the Perfect Custom Powerpoint Theme

Tips and Tricks for Designing the Perfect Custom Powerpoint Theme

Tech Trends 2024: The Coolest Gifts for the Savvy Gadget Geek

Tech Trends 2024: The Coolest Gifts for the Savvy Gadget Geek

Stateful Vs. Stateless VPNs in the Face of Threats

Stateful Vs. Stateless VPNs in the Face of Threats

Application Architecture Overview

Systems Analysis and Design Tutorial

An application system consists of three logical layers.

The presentation layer is what a system user sees or interacts with.  It can consist of visual objects such as screens, web pages or reports or non-visual objects such as an interactive voice response interface.

When most people think of application systems, they think mainly of the presentation layer.  Unfortunately, this layer represents a small portion of the effort involved in building application systems.

The business logic layer, on the other hand, implements and enforces the business rules via programming logic (computer instructions).

This business logic layer might on the surface appear to be very straight forward, however, that is rarely so.

Application Architecture Concepts

The data access layer consists of the definitions of database tables and columns and the computer logic that is needed to navigate the database.

The layer in the application architecture enforces rules regarding the storage and access of information. For example: All date fields must be valid dates.  All numeric fields must never contain alphanumeric characters.

This diagram on this page is a "logical" representation of an application system.  When a system is implemented, application system components can be physically deployed on different computer systems.

For example, the presentation of the web page you are looking at is being handled by your computer or mobile device.  The logic required to consolidate and communicate the visual objects that it needs is occurring on a web server located in Virginia USA.

blog banner

Web Application Architecture: How the Web Works

  • Engineering
  • 25 Jul, 2019
  • No comments Share

What is Web Application Architecture?

  • addresses a particular problem, even if it’s simply finding some information
  • is as interactive as a desktop application
  • has a Content Management System

How does the web request work?

web request-response cycle

Web request-response cycle

Web application architecture components and Three-Tier Architecture

web application architecture

Web application architecture following the three-tier pattern

Presentation layer

Business layer, persistence layer, example #1. dynamic web pages, spas, and mpas, single page applications.

SPA architecture

Single Page Application architecture

Multi-Page Applications

multi-page applications

MPA architecture

Example #2. Enterprise applications

enterprise application architecture

Enterprise application architecture

To conclude

Subscribe to our newsletter.

Stay tuned to the latest industry updates.

Latest Engineering Articles

Solution Architecture Explained

Solution Architecture Explained: Solving Business Problems with Technology

12 Techniques of Website Speed Optimization.jpg

12 Techniques of Website Speed Optimization: Performance Testing and Improvement Practices

secret key

OAuth Authorization Framework: How to Use It and Build Trust Online

Non-functional

Nonfunctional Requirements in Software Engineering: Examples, Types, Best Practices

Join us on the techtalks.

Discover new opportunities for your travel business, ask about the integration of certain technology, and of course - help others by sharing your experience.

Write an article for our blog

Almost 50 guest articles published from such contributors as Amadeus, DataQuest, MobileMonkey, and CloudFactory.

Software Architecture Patterns by

Get full access to Software Architecture Patterns and 60K+ other titles, with a free 10-day trial of O'Reilly.

There are also live events, courses curated by job role, and more.

Chapter 1. Layered Architecture

The most common architecture pattern is the layered architecture pattern, otherwise known as the n-tier architecture pattern. This pattern is the de facto standard for most Java EE applications and therefore is widely known by most architects, designers, and developers. The layered architecture pattern closely matches the traditional IT communication and organizational structures found in most companies, making it a natural choice for most business application development efforts. 

Pattern Description

Components within the layered architecture pattern are organized into horizontal layers, each layer performing a specific role within the application (e.g., presentation logic or business logic). Although the layered architecture pattern does not specify the number and types of layers that must exist in the pattern, most layered architectures consist of four standard layers: presentation, business, persistence, and database ( Figure 1-1 ). In some cases, the business layer and persistence layer are combined into a single business layer, particularly when the persistence logic (e.g., SQL or HSQL) is embedded within the business layer components. Thus, smaller applications may have only three layers, whereas larger and more complex business applications may contain five or more layers. 

Each layer of the layered architecture pattern has a specific role and responsibility within the application. For example, a presentation layer would be responsible for handling all user interface and browser communication logic, whereas a business layer would be responsible for executing specific business rules associated with the request. Each layer in the architecture forms an abstraction around the work that needs to be done to satisfy a particular business request. For example, the presentation layer doesn’t need to know or worry about how to get customer data; it only needs to display that information on a screen in particular format. Similarly, the business layer doesn’t need to be concerned about how to format customer data for display on a screen or even where the customer data is coming from; it only needs to get the data from the persistence layer, perform business logic against the data (e.g., calculate values or aggregate data), and pass that information up to the presentation layer.  

Alt Text

Figure 1-1. Layered architecture pattern

One of the powerful features of the layered architecture pattern is the separation of concerns among components. Components within a specific layer deal only with logic that pertains to that layer. For example, components in the presentation layer deal only with presentation logic, whereas components residing in the business layer deal only with business logic. This type of component classification makes it easy to build effective roles and responsibility models into your architecture, and also makes it easy to develop, test, govern, and maintain applications using this architecture pattern due to well-defined component interfaces and limited component scope.

Key Concepts

Notice in Figure 1-2 that each of the layers in the architecture is marked as being  closed . This is a very important concept in the layered architecture pattern. A closed layer means that as a request moves from layer to layer, it must go through the layer right below it to get to the next layer below that one. For example, a request originating from the presentation layer must first go through the business layer and then to the persistence layer before finally hitting the database layer. 

Alt Text

Figure 1-2. Closed layers and request access

So why not allow the presentation layer direct access to either the persistence layer or database layer? After all, direct database access from the presentation layer is much faster than going through a bunch of unnecessary layers just to retrieve or save database information. The answer to this question lies in a key concept known as  layers of isolation . 

The layers of isolation concept means that changes made in one layer of the architecture generally don’t impact or affect components in other layers: the change is isolated to the components within that layer, and possibly another associated layer (such as a persistence layer containing SQL). If you allow the presentation layer direct access to the persistence layer, then changes made to SQL within the persistence layer would impact both the business layer and the presentation layer, thereby producing a very tightly coupled application with lots of interdependencies between components. This type of architecture then becomes very hard and expensive to change.  

The layers of isolation concept also means that each layer is independent of the other layers, thereby having little or no knowledge of the inner workings of other layers in the architecture. To understand the power and importance of this concept, consider a large refactoring effort to convert the presentation framework from JSP (Java Server Pages) to JSF (Java Server Faces). Assuming that the contracts (e.g., model) used between the presentation layer and the business layer remain the same, the business layer is not affected by the refactoring and remains completely independent of the type of user-interface framework used by the presentation layer.  

While closed layers facilitate layers of isolation and therefore help isolate change within the architecture, there are times when it makes sense for certain layers to be open. For example, suppose you want to add a shared-services layer to an architecture containing common service components accessed by components within the business layer (e.g., data and string utility classes or auditing and logging classes). Creating a services layer is usually a good idea in this case because architecturally it restricts access to the shared services to the business layer (and not the presentation layer). Without a separate layer, there is nothing architecturally that restricts the presentation layer from accessing these common services, making it difficult to govern this access restriction.  

In this example, the new services layer would likely reside  below  the business layer to indicate that components in this services layer are not accessible from the presentation layer. However, this presents a problem in that the business layer is now required to go through the services layer to get to the persistence layer, which makes no sense at all. This is an age-old problem with the layered architecture, and is solved by creating open layers within the architecture.  

As illustrated in Figure 1-3 , the services layer in this case is marked as open,  meaning requests are allowed to bypass this open layer and go directly to the layer below it. In the following example, since the services layer is open, the business layer is now allowed to bypass it and go directly to the persistence layer, which makes perfect sense.  

Alt Text

Figure 1-3. Open layers and request flow

Leveraging the concept of open and closed layers helps define the relationship between architecture layers and request flows and also provides designers and developers with the necessary information to understand the various layer access restrictions within the architecture. Failure to document or properly communicate which layers in the architecture are open and closed (and why) usually results in tightly coupled and brittle architectures that are very difficult to test, maintain, and deploy.

Pattern Example

To illustrate how the layered architecture works, consider a request from a business user to retrieve customer information for a particular individual as illustrated in Figure 1-4 . The black arrows show the request flowing down to the database to retrieve the customer data, and the red arrows show the response flowing back up to the screen to display the data. In this example, the customer information consists of both customer data and order data (orders placed by the customer).  

The customer screen is responsible for accepting the request and displaying the customer information. It does not know where the data is, how it is retrieved, or how many database tables must be queries to get the data. Once the customer screen receives a request to get customer information for a particular individual, it then forwards that request onto the customer delegate module. This module is responsible for knowing which modules in the business layer can process that request and also how to get to that module and what data it needs (the contract). The customer object in the business layer is responsible for aggregating all of the information needed by the business request (in this case to get customer information). This module calls out to the  customer dao  (data access object) module in the persistence layer to get customer data, and also the order dao module to get order information. These modules in turn execute SQL statements to retrieve the corresponding data and pass it back up to the customer object in the business layer. Once the customer object receives the data, it aggregates the data and passes that information back up to the customer delegate, which then passes that data to the customer screen to be presented to the user.      

Alt Text

Figure 1-4. Layered architecture example

From a technology perspective, there are literally dozens of ways these modules can be implemented. For example, in the Java platform, the customer screen can be a (JSF) Java Server Faces screen coupled with the customer delegate as the managed bean component. The customer object in the business layer can be a local Spring bean or a remote EJB3 bean. The data access objects illustrated in the previous example can be implemented as simple POJO’s (Plain Old Java Objects), MyBatis XML Mapper files, or even objects encapsulating raw JDBC calls or Hibernate queries. From a Microsoft platform perspective, the customer screen can be an ASP (active server pages) module using the .NET framework to access C# modules in the business layer, with the customer and order data access modules implemented as ADO (ActiveX Data Objects). 

Considerations

The layered architecture pattern is a solid general-purpose pattern, making it a good starting point for most applications, particularly when you are not sure what architecture pattern is best suited for your application. However, there are a couple of things to consider from an architecture standpoint when choosing this pattern.

The first thing to watch out for is what is known as the architecture sinkhole anti-pattern . This anti-pattern describes the situation where requests flow through multiple layers of the architecture as simple pass-through processing with little or no logic performed within each layer. For example, assume the presentation layer responds to a request from the user to retrieve customer data. The presentation layer passes the request to the business layer, which simply passes the request to the persistence layer, which then makes a simple SQL call to the database layer to retrieve the customer data. The data is then passed all the way back up the stack with no additional processing or logic to aggregate, calculate, or transform the data. 

Every layered architecture will have at least some scenarios that fall into the architecture sinkhole anti-pattern. The key, however, is to analyze the percentage of requests that fall into this category. The 80-20 rule is usually a good practice to follow to determine whether or not you are experiencing the architecture sinkhole anti-pattern. It is typical to have around 20 percent of the requests as simple pass-through processing and 80 percent of the requests having some business logic associated with the request. However, if you find that this ratio is reversed and a majority of your requests are simple pass-through processing, you might want to consider making some of the architecture layers open, keeping in mind that it will be more difficult to control change due to the lack of layer isolation. 

Another consideration with the layered architecture pattern is that it tends to lend itself toward monolithic applications, even if you split the presentation layer and business layers into separate deployable units. While this may not be a concern for some applications, it does pose some potential issues in terms of deployment, general robustness and reliability, performance, and scalability.   

Pattern Analysis

The following table contains a rating and analysis of the common architecture characteristics for the layered architecture pattern. The rating for each characteristic is based on the natural tendency for that characteristic as a capability based on a typical implementation of the pattern, as well as what the pattern is generally known for. For a side-by-side comparison of how this pattern relates to other patterns in this report, please refer to  Appendix A  at the end of this report.

Get Software Architecture Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.

Don’t leave empty-handed

Get Mark Richards’s Software Architecture Patterns ebook to better understand how to design components—and how they should interact.

It’s yours, free.

Cover of Software Architecture Patterns

Check it out now on O’Reilly

Dive in for free with a 10-day trial of the O’Reilly learning platform—then explore all the other resources our members count on to build skills and solve problems every day.

presentation logic layer

Presentation Domain Data Layering

26 August 2015

Martin Fowler

team organization

encapsulation

application architecture

web development

One of the most common ways to modularize an information-rich program is to separate it into three broad layers: presentation (UI), domain logic (aka business logic), and data access. So you often see web applications divided into a web layer that knows about handling HTTP requests and rendering HTML, a business logic layer that contains validations and calculations, and a data access layer that sorts out how to manage persistent data in a database or remote services.

On the whole I've found this to be an effective form of modularization for many applications and one that I regularly use and encourage. It's biggest advantage (for me) is that it allows me to reduce the scope of my attention by allowing me to think about the three topics relatively independently. When I'm working on domain logic code I can mostly ignore the UI and treat any interaction with data sources as an abstract set of functions that give me the data I need and update it as I wish. When I'm working on the data access layer I focus on the details of wrangling the data into the form required by my interface. When I'm working on the presentation I can focus on the UI behavior, treating any data to display or update as magically appearing by function calls. By separating these elements I narrow the scope of my thinking in each piece, which makes it easier for me to follow what I need to do.

This narrowing of scope doesn't imply any sequence to programming them - I usually find I need to iterate between the layers. I might build the data and domain layers off my initial understanding of the UX, but when refining the UX I need to change the domain which necessitates a change to the data layer. But even with that kind of cross-layer iteration, I find it easier to focus on one layer at a time as I make changes. It's similar to the switching of thinking modes you get with refactoring's two hats .

Another reason to modularize is to allow me to substitute different implementations of modules. This separation allows me to build multiple presentations on top of the same domain logic without duplicating it. Multiple presentations could be separate pages in a web app, having a web app plus mobile native apps, an API for scripting purposes, or even an old fashioned command line interface. Modularizing the data source allows me to cope gracefully with a change in database technology, or to support services for persistence that may change with little notice. However I have to mention that while I often hear about data access substitution being a driver for separating the data source layer, I rarely hear of someone actually doing it.

Modularity also supports testability, which naturally appeals to me as a big fan of SelfTestingCode . Module boundaries expose seams that are good affordance for testing . UI code is often tricky to test, so it's good to get as much logic as you can into a domain layer which is easily tested without having to do gymnastics to access the program through a UI [1] . Data access is often slow and awkward, so using TestDoubles around the data layer often makes domain logic testing much easier and responsive.

While substitutability and testability are certainly benefits of this layering, I must stress that even without either of these reasons I would still divide into layers like this. The reduced scope of attention reason is sufficient on its own.

When talking about this we can either look at it as one pattern (presentation-domain-data) or split it into two patterns (presentation-domain, and domain-data). Both points of view are useful - I think of presentation-domain-data as a composite of presentation-domain and domain-data.

I consider these layers to be a form of module, which is a generic word I use for how we clump our software into relatively independent pieces. Exactly how this corresponds to code depends on the programming environment we're in. Usually the lowest level is some form of subroutine or function. An object-oriented language will have a notion of class that collects functions and data structure. Most languages have some form of higher level called packages or namespaces, which often can be formed into a hierarchy. Modules may correspond to separately deployable units: libraries, or services, but they don't have to.

Layering can occur at any of these levels. A small program may just put separate functions for the layers into different files. A larger system may have layers corresponding to namespaces with many classes in each.

I've mentioned three layers here, but it's common to see architectures with more than three layers. A common variation is to put a service layer between the domain and presentation, or to split the presentation layer into separate layers with something like Presentation Model . I don't find that more layers breaks the essential pattern, since the core separations still remain.

The dependencies generally run from top to bottom through the layer stack: presentation depends on the domain, which then depends on the data source. A common variation is to arrange things so that the domain does not depend on its data sources by introducing a mapper between the domain and data source layers. This approach is often referred to as a Hexagonal Architecture .

These layers are logical layers not physical tiers. I can run all three layers on my laptop, I can run the presentation and domain model in a desktop with a database on a server, I can split the presentation with a rich client in the browser and a Backed For Frontend on the server. In that case I treat the BFF as a presentation layer as it's focused on supporting a particular presentation option.

Although presentation-domain-data separation is a common approach, it should only be applied at a relatively small granularity. As an application grows, each layer can get sufficiently complex on its own that you need to modularize further. When this happens it's usually not best to use presentation-domain-data as the higher level of modules. Often frameworks encourage you to have something like view-model-data as the top level namespaces; that's OK for smaller systems, but once any of these layers gets too big you should split your top level into domain oriented modules which are internally layered.

Developers don't have to be full-stack but teams should be.

One common way I've seen this layering lead organizations astray is the AntiPattern of separating development teams by these layers. This looks appealing because front-end and back-end development require different frameworks (or even languages) making it easy for developers to specialize in one or the other. Putting those people with common skills together supports skill sharing and allows the organization to treat the team as a provider of a single, well-delineated type of work. In the same way, putting all the database specialists together fits in with the common centralization of databases and schemas. But the rich interplay between these layers necessitates frequent swapping between them. This isn't too hard when you have specialists in the same team who can casually collaborate, but team boundaries add considerable friction, as well as reducing an individual's motivation to develop the important cross-layer understanding of a system. Worse, separating the layers into teams adds distance between developers and users. Developers don't have to be full-stack (although that is laudable) but teams should be.

Further Reading

I've written about this separation from a number of different angles elsewhere. This layering drives the structure of P of EAA and chapter 1 of that book talks more about this layering. I didn't make this layering a pattern in its own right in that book but have toyed with that territory with Separated Presentation and PresentationDomainSeparation .

For more on why presentation-domain-data shouldn't be the highest level modules in a larger system, take a look at the writing and speaking of Simon Brown . I also agree with him that software architecture should be embedded in code.

I had a fascinating discussion with my colleague Badri Janakiraman about the nature of hexagonal architectures. The context was mostly around applications using Ruby on Rails, but much of the thinking applies to other cases when you may be considering this approach.

Acknowledgements

1: A PageObject is also an important tool to help testing around UIs.

:cake :Layered Architecture

Layered Architecture is a software design pattern that is widely used in modern software development. It is a logical and structured approach to software design that separates different functional modules of an application into four separate horizontal layers, each with a specific set of responsibilities. This separation of concerns makes the code more modular, maintainable, and scalable, and enables easier testing and debugging.

This particular architectural pattern has influenced the development of various other architectural patterns, including:

  • Hexagonal Architecture (also known as Ports and Adapters)
  • Onion Architecture
  • Clean Architecture

These patterns have emerged in response to the need to clarify further the concept of layered architecture, and they have each added their own unique features and benefits. However, all these patterns have in common the goal to provide a more modular, flexible, and maintainable approach to building software systems.

Therefore, we strongly recommend understanding the core principles of layered architecture and its relationship to these other patterns, as it will help you better understand these other software architecture patterns, and help you make informed decisions about which approach is best suited to your specific needs and requirements.

In this article, we will focus on the over-arching Layered Architecture , explaining its key principles, benefits, and implementation strategies. We will also discuss some real-world examples of successful implementation and highlight the advantages of using Layered Architecture in modern software development.

What exactly is layered architecture?

Layered architecture is a common pattern used in software design, where the application is divided into different layers based on their functionality. In a four-layered architecture, the layers are typically divided into:

  • Presentation
  • Application
  • Infrastructure

These layers are arranged in a hierarchical order, where each layer provides services to the layer above it and uses services from the layer below it, and each layer is responsible for handling specific tasks and has limited communication with the other layers.

This helps to improve modularity and allows for better separation of concerns. The architecture is called "layered" because it resembles a layered cake, where each layer is independent of the others but builds on them to form a complete and cohesive application.

  • Presentation Layer

The presentation layer is the topmost layer of the architecture, responsible for handling the user interface and displaying data to the user. This layer interacts with the application layer to retrieve the data and provides a visual representation of the data to the user. In web applications, this layer is often implemented using HTML, CSS, and JavaScript.

  • Application Layer

The application layer is responsible for handling business logic and coordinating interactions between different components. This layer receives input from the presentation layer and processes it before passing it down to the domain layer. It is also responsible for communicating with external systems and services. Think of this layer as the maestro in an orchestra, that guides the musicians on what, when and how to play their instrument, but who doesn't actually play any instrument himself. Similarly, the Application Layer doesn't do anything per se, but it tells the domain layer what and when it should do something.

  • Domain Layer

The domain layer contains the business logic and rules of the application. This layer represents the core of the application and defines how the application processes data and interacts with the external world. It is responsible for ensuring the consistency and validity of the data and defines the behavior of the application. Here is where you'll find the algorithms, the programming compoenents, the functions, etc. Its really the heart of the application and generally what adds most value to the application itself.

  • Infrastructure Layer

The infrastructure layer is responsible for handling external dependencies and providing services to the other layers. This layer interacts with databases, file systems, and other external systems. It also provides services such as logging, caching, and authentication to the other layers. By separating infrastructure concerns from the rest of the application, it becomes easier to maintain and replace external dependencies without affecting the core functionality of the application.

  • Advantages of Layered Architecture

Layered architecture offers several advantages that make it a popular choice for large and complex software systems.

Modular structure: By dividing the application into different layers, developers can isolate specific functionalities and easily modify or replace them without affecting other parts of the system. This allows for more agile development and easier maintenance.

Separation of concerns: Each layer is responsible for a specific set of tasks, and there is limited communication between the layers. This helps to ensure that the code is organized and easy to understand, making it easier to test and debug. This ensures a clear separation of the application's functionality and the underlying technology, allowing for better scalability, as additional layers can be added to handle increased functionality without affecting the existing layers.

For example, the presentation layer can be implemented using different technologies, such as a web-based user interface or a mobile app, without affecting the business or data access layers. This flexibility makes it easier to adapt the application to different environments or requirements.
  • Code reusability: Because each layer has a well-defined interface, it is possible to reuse code across different applications or even different layers of the same application. This can save developers time and effort by reducing the amount of code they need to write and maintain.

In large and complex software systems, layered architecture is particularly important. These systems often involve multiple teams of developers working on different parts of the system simultaneously. Layered architecture helps to promote modularity and separation of concerns, making it easier for teams to work independently without stepping on each other's toes. It also makes it easier to manage and maintain the codebase over time, as the structure of the system is well-defined and easy to understand.

Additionally, layered architecture helps to ensure that the system remains robust and reliable. By dividing the application into different layers, developers can focus on specific functionalities and ensure that they are working correctly. This helps to reduce the likelihood of bugs or errors that could cause the system to fail. It also makes it easier to identify and fix issues when they do occur, as the problem is likely to be isolated to a specific layer rather than affecting the entire system.

  • Implementing Layered Architecture

Implementing Layered Architecture involves defining the interfaces and responsibilities of each layer and the interactions between them. Here are some steps to follow when implementing Layered Architecture:

Define the layers: Identify the different layers of the application and their responsibilities. The layers should be as independent as possible, with clear and well-defined interfaces. A good practice is to use a dependency injection framework to manage the dependencies between the layers.

Implement the layers: Develop the classes and functions that implement the functionality of each layer. The classes should only interact with the layer above or below them and should not depend on other layers. Each layer should have its own set of tests to ensure its functionality and integration with the other layers.

Define the interfaces: Define the interfaces between the layers, specifying the methods and parameters that each layer requires from the layer below it. The interfaces should be simple and focused on the specific needs of each layer. The interfaces should be designed to be easy to use, easy to understand, and easy to test.

Handle exceptions: Define how exceptions will be handled between the layers. A good practice is to catch exceptions in the lower layers and convert them to more specific exceptions in the higher layers. This approach helps to keep the application logic separated from the exception handling logic and facilitates debugging.

Test and validate the layers: Once the layers are implemented, test them individually and in combination. Validate that the layers work correctly, that the interfaces are well defined and easy to use, and that the application behaves as expected.

Monitor and maintain the layers: Once the application is in production, monitor and maintain the layers. Ensure that the layers are stable, scalable, and secure. Make any necessary changes to the layers to optimize performance, improve security, or fix bugs.

In summary, implementing a layered architecture is definitely a bit more work than simply not thinking about this, however, its very clear that most developers follow a similar thought process when starting a new project. Therefore, its worth investing just a bit more time into this design process as it will help you build better quality software going forward.

  • Use cases and real-world examples

There are numerous real-world examples of successful implementations of Layered Architecture in various organizations. One such example is the Apache Struts framework, which is widely used for building Java-based web applications. The Struts framework uses a three-layered architecture that separates the presentation, business logic, and data access layers. This has made it easier for developers to maintain and extend the framework, as well as to customize it to meet specific business requirements.

Another example is the Spring framework, which is also widely used for building Java-based web applications. The Spring framework uses a four-layered architecture that includes a presentation layer, a business logic layer, a persistence layer, and a data access layer. This layered approach has made it easier for developers to build scalable, robust, and flexible web applications that can handle large volumes of traffic and complex business logic.

Organizations that have adopted Layered Architecture have benefited from several advantages. Firstly, this approach provides a clear separation of concerns between different layers, which makes it easier to manage complexity and maintainability in larger, more complex software systems. This separation of concerns also allows developers to work more efficiently, as they can focus on specific areas of the application without worrying about the impact on other parts of the system.

Secondly, Layered Architecture enables organizations to achieve better performance and scalability in their software systems. By separating the business logic and data access layers, for example, organizations can optimize each layer for specific performance requirements and improve the overall efficiency of the system.

Lastly, Layered Architecture also supports better reusability and flexibility in software systems. By encapsulating functionality within separate layers, organizations can more easily reuse and extend different components of the system without impacting other parts of the architecture. This can help organizations to build more modular and maintainable software systems that can adapt to changing business requirements over time.

Layered architecture is a fundamental software design pattern that provides a clear separation of concerns and promotes modularity and flexibility in software systems. It allows for the development of robust, scalable, and maintainable applications that can adapt to changing business requirements.

Through understanding the principles and benefits of layered architecture, developers can effectively implement this pattern in their own software projects. With the clear separation of concerns, each layer can be developed and maintained independently, allowing for better code reuse, easier testing, and overall improved software quality.

The importance of using layered architecture in modern software development cannot be overstated. As software systems become increasingly complex, layered architecture provides a scalable and adaptable approach to designing and maintaining such systems. It is a proven methodology that has been successfully implemented in many real-world scenarios.

We encourage developers to start implementing layered architecture in their own software projects. By doing so, they can reap the many benefits that this design pattern has to offer, including improved software quality, easier maintenance, and increased scalability. With careful planning and implementation, layered architecture can be a powerful tool in the development of successful software systems.

  • Additional resources

Here are a few additional references with regards to Layered Architecture:

  • The Layered Architecture Pattern in Software Architecture - Article by Kayvan Kaseb
  • Layered Architecture - Article by Herberto Graça
  • Software Architecture Patterns — Layered Architecture - Article by Priyal Walpita

Application Architecture Guide - Chapter 10 - Presentation Layer Guidelines

Note - The patterns & practices Microsoft Application Architecture Guide, 2nd Edition is now live at http://msdn.microsoft.com/en-us/library/dd673617.aspx .

- J.D. Meier, Alex Homer, David Hill, Jason Taylor, Prashant Bansode, Lonnie Wall, Rob Boucher Jr, Akshay Bogawat

  • 1 Objectives
  • 3 Presentation Layer Components
  • 5 Design Considerations
  • 6 Presentation Layer Frame
  • 8 Composition
  • 9 Exception Management
  • 12 Navigation
  • 13 Presentation Entities
  • 14 Request Processing
  • 15 User Experience
  • 16 UI Components
  • 17 UI Process Components
  • 18 Validation
  • 19 Pattern Map
  • 20 Pattern Descriptions
  • 21.1 Mobile Applications
  • 21.2 Rich Client Applications
  • 21.3 Rich Internet Applications (RIA)
  • 21.4 Web Applications
  • 22 patterns & practices Solution Assets
  • 23 Additional Resources
  • Understand how the presentation layer fits into typical application architecture.
  • Understand the components of the presentation layer.
  • Learn the steps for designing the presentation layer.
  • Learn the common issues faced while designing the presentation layer.
  • Learn the key guidelines for designing the presentation layer.
  • Learn the key patterns and technology considerations for designing the presentation layer.

The presentation layer contains the components that implement and display the user interface and manage user interaction. This layer includes controls for user input and display, in addition to components that organize user interaction. Figure 1 shows how the presentation layer fits into a common application architecture.

presentation logic layer

Figure 1 A typical application showing the presentation layer and the components it may contain

Presentation Layer Components

  • User interface (UI) components . User interface components provide a way for users to interact with the application. They render and format data for users. They also acquire and validate data input by the user.
  • User process components . User process components synchronize and orchestrate user interactions. Separate user process components may be useful if you have a complicated UI. Implementing common user interaction patterns as separate user process components allows you to reuse them in multiple UIs.

The following steps describe the process you should adopt when designing the presentation layer for your application. This approach will ensure that you consider all of the relevant factors as you develop your architecture:

  • Identify your client type . Choose a client type that satisfies your requirements and adheres to the infrastructure and deployment constraints of your organization. For instance, if your users are on mobile devices and will be intermittently connected to the network, a mobile rich client is probably your best choice.
  • Determine how you will present data . Choose the data format for your presentation layer and decide how you will present the data in your UI.
  • Determine your data-validation strategy . Use data-validation techniques to protect your system from untrusted input.
  • Determine your business logic strategy . Factor out your business logic to decouple it from your presentation layer code.
  • Determine your strategy for communication with other layers . If your application has multiple layers, such as a data access layer and a business layer, determine a strategy for communication between your presentation layer and other layers.

Design Considerations

There are several key factors that you should consider when designing your presentation layer. Use the following principles to ensure that your design meets the requirements for your application, and follows best practices:

  • Choose the appropriate UI technology. Determine if you will implement a rich (smart) client, a Web client, or a rich Internet application (RIA). Base your decision on application requirements, and on organizational and infrastructure constraints.
  • Use the relevant patterns. Review the presentation layer patterns for proven solutions to common presentation problems.
  • Design for separation of concerns. Use dedicated UI components that focus on rendering and display. Use dedicated presentation entities to manage the data required to present your views. Use dedicated UI process components to manage the processing of user interaction.
  • Consider human interface guidelines. Review your organization’s guidelines for UI design. Review established UI guidelines based on the client type and technologies that you have chosen.
  • Adhere to user-driven design principles. Before designing your presentation layer, understand your customer. Use surveys, usability studies, and interviews to determine the best presentation design to meet your customer’s requirements.

Presentation Layer Frame

There are several common issues that you must consider as your develop your design. These issues can be categorized into specific areas of the design. The following table lists the common issues for each category where mistakes are most often made.

Table 1 Presentation Layer Frame

Caching is one of the best mechanisms you can use to improve application performance and UI responsiveness. Use data caching to optimize data lookups and avoid network round trips. Cache the results of expensive or repetitive processes to avoid unnecessary duplicate processing.

Consider the following guidelines when designing your caching strategy:

  • Do not cache volatile data.
  • Consider using ready-to-use cache data when working with an in-memory cache. For example, use a specific object instead of caching raw database data.
  • Do not cache sensitive data unless you encrypt it.
  • If your application is deployed in Web farm, avoid using local caches that need to be synchronized; instead, consider using a transactional resource manager such as Microsoft SQL Server® or a product that supports distributed caching.
  • Do not depend on data still being in your cache. It may have been removed.

Composition

Consider whether your application will be easier to develop and maintain if the presentation layer uses independent modules and views that are easily composed at run time. Composition patterns support the creation of views and the presentation layout at run time. These patterns also help to minimize code and library dependencies that would otherwise force recompilation and redeployment of a module when the dependencies change. Composition patterns help you to implement sharing, reuse, and replacement of presentation logic and views.

Consider the following guidelines when designing your composition strategy:

  • Avoid using dynamic layouts. They can be difficult to load and maintain.
  • Be careful with dependencies between components. For example, use abstraction patterns when possible to avoid issues with maintainability.
  • Consider creating templates with placeholders. For example, use the Template View pattern to compose dynamic Web pages in order to ensure reuse and consistency.
  • Consider composing views from reusable modular parts. For example, use the Composite View pattern to build a view from modular, atomic component parts.
  • If you need to allow communication between presentation components, consider implementing the Publish/Subscribe pattern. This will lower the coupling between the components and improve testability.

Exception Management

Design a centralized exception-management mechanism for your application that catches and throws exceptions consistently. Pay particular attention to exceptions that propagate across layer or tier boundaries, as well as exceptions that cross trust boundaries. Design for unhandled exceptions so they do not impact application reliability or expose sensitive information.

Consider the following guidelines when designing your exception management strategy:

  • Use user-friendly error messages to notify users of errors in the application.
  • Avoid exposing sensitive data in error pages, error messages, log files, and audit files.
  • Design a global exception handler that displays a global error page or an error message for all unhandled exceptions.
  • Differentiate between system exceptions and business errors. In the case of business errors, display a user-friendly error message and allow the user to retry the operation. In the case of system exceptions, check to see if the exception was caused by issues such as system or database failure, display a user-friendly error message, and log the error message, which will help in troubleshooting.
  • Avoid using exceptions to control application logic.

Design a user input strategy based on your application input requirements. For maximum usability, follow the established guidelines defined in your organization, and the many established industry usability guidelines based on years of user research into input design and mechanisms.

Consider the following guidelines when designing your input collection strategy:

  • Use forms-based input controls for normal data-collection tasks.
  • Use a document-based input mechanism for collecting input in Microsoft Office–style documents.
  • Implement a wizard-based approach for more complex data collection tasks, or for input that requires a workflow.
  • Design to support localization by avoiding hard-coded strings and using external resources for text and layout.
  • Consider accessibility in your design. You should consider users with disabilities when designing your input strategy; for example, implement text-to-speech software for blind users, or enlarge text and images for users with poor sight. Support keyboard-only scenarios where possible for users who cannot manipulate a pointing device.

Design your UI layout so that the layout mechanism itself is separate from the individual UI components and UI process components. When choosing a layout strategy, consider whether you will have a separate team of designers building the layout, or whether the development team will create the UI. If designers will be creating the UI, choose a layout approach that does not require code or the use of development-focused tools.

Consider the following guidelines when designing your layout strategy:

  • Use templates to provide a common look and feel to all of the UI screens.
  • Use a common look and feel for all elements of your UI to maximize accessibility and ease of use.
  • Consider device-dependent input, such as touch screens, ink, or speech, in your layout. For example, with touch-screen input you will typically use larger buttons with more spacing between them than you would with mouse or keyboard inputs.
  • When building a Web application, consider using Cascading Style Sheets (CSS) for layout. This will improve rendering performance and maintainability.
  • Use design patterns, such as Model-View-Presenter (MVP), to separate the layout design from interface processing.

Design your navigation strategy so that users can navigate easily through your screens or pages, and so that you can separate navigation from presentation and UI processing. Ensure that you display navigation links and controls in a consistent way throughout your application to reduce user confusion and hide application complexity.

Consider the following guidelines when designing your navigation strategy:

  • Use well-known design patterns to decouple the UI from the navigation logic where this logic is complex.
  • Design toolbars and menus to help users find functionality provided by the UI.
  • Consider using wizards to implement navigation between forms in a predictable way.
  • Determine how you will preserve navigation state if the application must preserve this state between sessions.
  • Consider using the Command Pattern to handle common actions from multiple sources.

Presentation Entities

Use presentation entities to store the data you will use in your presentation layer to manage your views. Presentation entities are not always necessary; use them only if your datasets are sufficiently large and complex to require separate storage from the UI controls.

Consider the following guidelines when designing presentation entities:

  • Determine if you require presentation entities. Typically, you may require presentation entities only if the data or the format to be displayed is specific to the presentation layer.
  • If you are working with data-bound controls, consider using custom objects, collections, or datasets as your presentation entity format.
  • If you want to map data directly to business entities, use a custom class for your presentation entities.
  • Do not add business logic to presentation entities.
  • If you need to perform data type validation, consider adding it in your presentation entities.

Request Processing

Design your request processing with user responsiveness in mind, as well as code maintainability and testability.

Consider the following guidelines when designing request processing:

  • Use asynchronous operations or worker threads to avoid blocking the UI for long-running actions.
  • Avoid mixing your UI processing and rendering logic.
  • Consider using the Passive View pattern (a variant of MVP) for interfaces that do not manage a lot of data.
  • Consider using the Supervising Controller pattern (a variant of MVP) for interfaces that manage large amounts of data.

User Experience

Good user experience can make the difference between a usable and unusable application. Carry out usability studies, surveys, and interviews to understand what users require and expect from your application, and design with these results in mind.

Consider the following guidelines when designing for user experience:

  • When developing a rich Internet application (RIA), avoid synchronous processing where possible.
  • When developing a Web application, consider using Asynchronous JavaScript and XML (AJAX) to improve responsiveness and to reduce post backs and page reloads.
  • Do not design overloaded or overly complex interfaces. Provide a clear path through the application for each key user scenario.
  • Design to support user personalization, localization, and accessibility.
  • Design for user empowerment. Allow the user to control how he or she interacts with the application, and how it displays data to them.

UI Components

UI components are the controls and components used to display information to the user and accept user input. Be careful not to create custom controls unless it is necessary for specialized display or data collection.

Consider the following guidelines when designing UI components:

  • Take advantage of the data-binding features of the controls you use in the UI.
  • Create custom controls or use third-party controls only for specialized display and data-collection tasks.
  • When creating custom controls, extend existing controls if possible instead of creating a new control.
  • Consider implementing designer support for custom controls to make it easier to develop with them.
  • Consider maintaining the state of controls as the user interacts with the application instead of reloading controls with each action.

UI Process Components

UI process components synchronize and orchestrate user interactions. UI processing components are not always necessary; create them only if you need to perform significant processing in the presentation layer that must be separated from the UI controls. Be careful not to mix business and display logic within the process components; they should be focused on organizing user interactions with your UI.

Consider the following guidelines when designing UI processing components:

  • Do not create UI process components unless you need them.
  • If your UI requires complex processing or needs to talk to other layers, use UI process components to decouple this processing from the UI.
  • Consider dividing UI processing into three distinct roles: Model, View, and Controller/Presenter, by using the MVC or MVP pattern.
  • Avoid business rules, with the exception of input and data validation, in UI processing components.
  • Consider using abstraction patterns, such as dependency inversion, when UI processing behavior needs to change based on the run-time environment.
  • Where the UI requires complex workflow support, create separate workflow components that use a workflow system such as Windows Workflow or a custom mechanism.

Designing an effective input and data-validation strategy is critical to the security of your application. Determine the validation rules for user input as well as for business rules that exist in the presentation layer.

Consider the following guidelines when designing your input and data validation strategy:

  • Validate all input data on the client side where possible to improve interactivity and reduce errors caused by invalid data.
  • Do not rely on client-side validation only. Always use server-side validation to constrain input for security purposes and to make security-related decisions.
  • Design your validation strategy to constrain, reject, and sanitize malicious input.
  • Use the built-in validation controls where possible, when working with .NET Framework.
  • In Web applications, consider using AJAX to provide real-time validation.

Pattern Map

Key patterns are organized by key categories, as detailed in the Presentation Layer Frame in the following table. Consider using these patterns when making design decisions for each category.

Table 2 Pattern Map

  • For more information on the Page Cache pattern, see “Enterprise Solution Patterns Using Microsoft .NET” at http://msdn.microsoft.com/en-us/library/ms998469.aspx
  • For more information on the Model-View-Controller (MVC), Page Controller, Front Controller, Template View, Transform View, and Two-Step View patterns, see “Patterns of Enterprise Application Architecture (P of EAA)” at http://martinfowler.com/eaaCatalog/
  • For more information on the Composite View, Supervising Controller, and Presentation Model patterns, see “Patterns in the Composite Application Library” at http://msdn.microsoft.com/en-us/library/cc707841.aspx
  • For more information on the Chain of responsibility and Command pattern, see “data & object factory” at http://www.dofactory.com/Patterns/Patterns.aspx
  • For more information on the Asynchronous Callback pattern, see “Creating a Simplified Asynchronous Call Pattern for Windows Forms Applications” at http://msdn.microsoft.com/en-us/library/ms996483.aspx
  • For more information on the Exception Shielding and Entity Translator patterns, see “Useful Patterns for Services” at http://msdn.microsoft.com/en-us/library/cc304800.aspx

Pattern Descriptions

  • Asynchronous Callback. Execute long-running tasks on a separate thread that executes in the background, and provide a function for the thread to call back into when the task is complete.
  • Cache Dependency. Use external information to determine the state of data stored in a cache.
  • Chain of Responsibility. Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request.
  • Composite View . Combine individual views into a composite representation.
  • Command Pattern. Encapsulate request processing in a separate command object with a common execution interface.
  • Entity Translator. An object that transforms message data types into business types for requests, and reverses the transformation for responses.
  • Exception Shielding. Prevent a service from exposing information about its internal implementation when an exception occurs.
  • Front Controller . Consolidate request handling by channeling all requests through a single handler object, which can be modified at run time with decorators.
  • Model-View-Controller . Separate the UI code into three separate units: Model (data), View (interface), and Presenter (processing logic), with a focus on the View. Two variations on this pattern include Passive View and Supervising Controller, which define how the View interacts with the Model.
  • Page Cache. Improve the response time for dynamic Web pages that are accessed frequently but change less often and consume a large amount of system resources to construct.
  • Page Controller . Accept input from the request and handle it for a specific page or action on a Web site.
  • Passive View . Reduce the view to the absolute minimum by allowing the controller to process user input and maintain the responsibility for updating the view.
  • Presentation Model . Move all view logic and state out of the view, and render the view through data-binding and templates.
  • Supervising Controller . A variation of the MVC pattern in which the controller handles complex logic, in particular coordinating between views, but the view is responsible for simple view-specific logic.
  • Template View . Implement a common template view, and derive or construct views using this template view.
  • Transform View . Transform the data passed to the presentation tier into HTML for display in the UI.
  • Two-Step View . Transform the model data into a logical presentation without any specific formatting, and then convert that logical presentation to add the actual formatting required.

Technology Considerations

The following guidelines will help you to choose an appropriate implementation technology. The guidelines also contain suggestions for common patterns that are useful for specific types of application and technology.

Mobile Applications

Consider the following guidelines when designing a mobile application:

  • If you want to build full-featured connected, occasionally connected, and disconnected executable applications that run on a wide range of Microsoft Windows®–based devices, consider using the Microsoft Windows Compact Framework.
  • If you want to build connected applications that require Wireless Application Protocol (WAP), compact HTML (cHTML), or similar rendering formats, consider using ASP.NET Mobile Forms and Mobile Controls.
  • If you want to build applications that support rich media and interactivity, consider using Microsoft Silverlight® for Mobile.

Rich Client Applications

Consider the following guidelines when designing a rich client application:

  • If you want to build applications with good performance and interactivity, and have design support in Microsoft Visual Studio®, consider using Windows Forms.
  • If you want to build applications that fully support rich media and graphics, consider using Windows Presentation Foundation (WPF).
  • If you want to build applications that are downloaded from a Web server and then execute on the client, consider using XAML Browser Applications (XBAP).
  • If you want to build applications that are predominantly document-based, or are used for reporting, consider designing a Microsoft Office Business Application.
  • If you decide to use Windows Forms and you are designing composite interfaces, consider using the Smart Client Software Factory.
  • If you decide to use WPF and you are designing composite interfaces, consider using the Composite Application Guidance for WPF.
  • If you decide to use WPF, consider using the Presentation Model (Model-View-ViewModel) pattern.
  • If you decide to use WPF, consider using WPF Commands to communicate between your View and your Presenter or ViewModel.
  • If you decide to use WPF, consider implementing the Presentation Model pattern by using DataTemplates over User Controls to give designers more control.

Rich Internet Applications (RIA)

Consider the following guidelines when designing an RIA:

  • If you want to build browser-based, connected applications that have broad cross-platform reach, are highly graphical, and support rich media and presentation features, consider using Silverlight.
  • If you decide to use Silverlight, consider using the Presentation Model (Model-View-ViewModel) pattern.

Web Applications

Consider the following guidelines when designing a Web application:

  • If you want to build applications that are accessed through a Web browser or specialist user agent, consider using ASP.NET.
  • If you want to build applications that provide increased interactivity and background processing, with fewer page reloads, consider using ASP.NET with AJAX.
  • If you want to build applications that include islands of rich media content and interactivity, consider using ASP.NET with Silverlight controls.
  • If you are using ASP.NET and want to implement a control-centric model with separate controllers and improved testability, consider using the ASP.NET MVC Framework.
  • If you are using ASP.NET, consider using master pages to simplify development and implement a consistent UI across all pages.

patterns & practices Solution Assets

  • Web Client Software Factory at http://msdn.microsoft.com/en-us/library/bb264518.aspx
  • Smart Client Software Factory at http://msdn.microsoft.com/en-us/library/aa480482.aspx
  • Composite Application Guidance for WPF at http://msdn.microsoft.com/en-us/library/cc707819.aspx
  • Smart Client - Composite UI Application Block at http://msdn.microsoft.com/en-us/library/aa480450.aspx

Additional Resources

  • For more information, see Microsoft Inductive User Interface Guidelines at http://msdn.microsoft.com/en-us/library/ms997506.aspx .
  • For more information, see User Interface Control Guidelines at http://msdn.microsoft.com/en-us/library/bb158625.aspx .
  • For more information, see User Interface Text Guidelines at http://msdn.microsoft.com/en-us/library/bb158574.aspx .
  • For more information, see Design and Implementation Guidelines for Web Clients at http://msdn.microsoft.com/en-us/library/ms978631.aspx .
  • For more information, see Web Presentation Patterns at http://msdn.microsoft.com/en-us/library/ms998516.aspx .

Navigation menu

Page actions.

  • View source

Personal tools

  • Community portal
  • Current events
  • Recent changes
  • Random page
  • What links here
  • Related changes
  • Special pages
  • Printable version
  • Permanent link
  • Page information

Powered by MediaWiki

  • This page was last edited on 22 January 2010, at 02:50.
  • Privacy policy
  • About Guidance Share
  • Disclaimers

N-Tier Architecture Presentation Logic Layer

The Presentation Layer in an N-Tier structure is commonly referred to as the “client” layer. It consists of parts that are used to present data to an end user. Examples of components on the Presentation Layer might include edit boxes, labels, text boxes, grids, buttons, Windows or Web forms, or more. The Presentation Layer can be either Windows based or Internet based.

What an Internet Based Presentation Layer Looks Like

Let us take a look of a correctly formatted Presentation Layer. This one consists of a Web server (IIS, in this instance), Web Pages, and Web Components.

All of this will be seen by the end user on a browser, such as Internet Explorer. Simple, right?

Now let’s take a look at a more in depth Presentation Logic Layer.

N-Tier Layers Close-Up

Presentation logic layer close-up.

As you can see by the diagram above, the Presentation Logic Layer works so as to provide your user with an interface in to your application. It consists of standard things you are probably already quite familiar with, including Windows forms and ASP documents. It thus relies on the results generated by the Business Tier in order to transform data in to something that can be used, read, and understood by the end user. 

The presentation layer is also sometimes referred to as the client layer. It consists of components that serve to present data to the end user. This data might include Windows or online buttons and forms, boxes for editing or texts, grids, labels, and more. In short, the presentation layer is a key component of any N-Tier system; without it, as the name infers, nothing will be presented to the end user, no matter how well the system functions otherwise.

Author description.

Avatar

Editorial Team at Exforsys is a team of IT Consulting and Training team led by Chandra Vennapoosa.

Free Training

What is n-tier, three tier software architectures.

  • Client-Server Models and N-Tier Applications
  • N-Tier Application Manageability
  • N-Tier Application Partitioning
  • N-Tier Architecture: The Business Rules Layer
  • N-Tier Architecture: Data Access Layer

Exforsys e-Newsletter

ebook

Related Articles

Latest articles.

  • Project Management Techniques
  • Product Development Best Practices
  • Importance of Quality Data Management
  • How to Maximize Quality Assurance
  • Utilizing Effective Quality Assurance Strategies

Privacy Overview

This site uses cookies to deliver our services and to show you relevant ads and job listings. By using our site, you acknowledge that you have read and understand our Cookie Policy , Privacy Policy , and our Terms of Service . Your use of Exforsys’s Products and Services, including the Exforsys Inc Network, is subject to these policies and terms.

logo

Exploring the 3 layers of software interactions (APIs)

apply

Application Programming Interfaces, commonly known as APIs, are a set of protocols, routines, and tools that enable software applications to interact with each other. They allow different software applications to exchange information seamlessly and efficiently.

APIs have become increasingly important in today's digital world, as they enable developers to build powerful applications that can connect with other services and platforms. APIs can be broken down into three different layers, each of which serves a different purpose.

In this blog post, we will explore the three layers of APIs and what they do.

1. Presentation Layer

The presentation layer, also known as the "API endpoint," is the layer that developers interact with most frequently. This layer provides a user-friendly interface for developers to access the functionality and data of the underlying service. It is responsible for processing incoming requests and returning responses in a format that developers can easily understand.

The presentation layer can take many different forms, depending on the requirements of the API. It could be a REST API that uses HTTP requests to exchange data or a SOAP API that uses XML messages to communicate. Regardless of the specific implementation, the presentation layer is the public-facing aspect of the API and is the first point of contact for developers.

2. Business Logic Layer

The business logic layer, also known as the "API middleware," is the layer that contains the core logic of the API. It is responsible for processing the requests received from the presentation layer and generating responses based on the requested actions.

The business logic layer is where the API's core functionality resides. It may perform data validation, authentication and authorization, database queries, or other complex operations. This layer is typically developed by the service provider and is not exposed directly to developers.

3. Data Storage Layer

The data storage layer, also known as the "API database," is the layer where all of the data used by the API is stored. This layer is responsible for managing data storage, retrieval, and modification. It may use a variety of database technologies such as SQL, NoSQL, or object-oriented databases.

The data storage layer is the most critical component of the API since it holds the data that the API relies on. If the data storage layer fails, the entire API may fail. Therefore, it is crucial to ensure that the data storage layer is designed and implemented correctly.

In conclusion, APIs consist of three layers: presentation layer, business logic layer, and data storage layer. Each layer plays a crucial role in the API's functionality and performance. Understanding the three layers of an API is essential for developers looking to build robust, reliable, and scalable APIs.

Related articles

article

What is Application Programming Interface (API)?

An API is a set of rules and practices that allow two applications to communicate. This means that one can use one application to retrieve data from another application or send data to another application.

Web Analytics

Flutter App Architecture: The Presentation Layer

Andrea Bizzotto

Andrea Bizzotto

Updated   Sep 21, 2023 11 min read

When writing Flutter apps, separating any business logic from the UI code is very important.

This makes our code more testable and easier to reason about , and is especially important as our apps become more complex.

To accomplish this, we can use design patterns to introduce a separation of concerns between different components in our app.

And for reference, we can adopt a layered app architecture such as the one represented in this diagram:

I have already covered some of the layers above in other articles:

  • Flutter App Architecture with Riverpod: An Introduction
  • Flutter App Architecture: The Repository Pattern
  • Flutter App Architecture: The Domain Model
  • Flutter App Architecture: The Application Layer

And this time, we will focus on the presentation layer and learn how we can use controllers to:

  • hold business logic
  • manage the widget state
  • interact with repositories in the data layer
This kind of controller is the same as the view model that you would use in the MVVM pattern . If you've worked with flutter_bloc before, it has the same role as a cubit .

We will learn about the AsyncNotifier class, which is a replacement for the StateNotifier and the ValueNotifier / ChangeNotifier classes in the Flutter SDK.

And to make this more useful, we will implement a simple authentication flow as an example.

Ready? Let's go!

A simple authentication flow

Let's consider a very simple app that we can use to sign in anonymously and toggle between two screens:

And in this article, we'll focus on how to implement:

  • an auth repository that we can use to sign in and sign out
  • a sign-in widget screen that we show to the user
  • the corresponding controller class that mediates between the two

Here's a simplified version of the reference architecture for this specific example:

You can find the complete source code for this app on GitHub . For more info about how it is organized, read this: Flutter Project Structure: Feature-first or Layer-first?

The AuthRepository class

As a starting point, we can define a simple abstract class that contains three methods that we'll use to sign in, sign out, and check the authentication state:

In practice, we also need a concrete class that implements AuthRepository . This could be based on Firebase or any other backend. We can even implement it with a fake repository for now. For more details, see this article about the repository pattern .

For completeness, we can also define a simple AppUser model class:

And if we use Riverpod, we also need a Provider that we can use to access our repository:

Next up, let's focus on the sign-in screen.

The SignInScreen widget

Suppose we have a simple SignInScreen widget defined like so:

This is just a simple Scaffold with an ElevatedButton in the middle.

Note that since this class extends ConsumerWidget , in the build() method we have an extra ref object that we can use to access providers as needed.

Accessing the AuthRepository directly from our widget

As a next step, we can use the onPressed callback to sign in like so:

This code works by obtaining the AuthRepository with a call to ref.read(authRepositoryProvider) . and calling the signInAnonymously() method on it.

This covers the happy path (sign-in successful). But we should also account for loading and error states by:

  • disabling the sign-in button and showing a loading indicator while sign-in is in progress
  • showing a SnackBar or alert if the call fails for any reason

The "StatefulWidget + setState" way

One simple way of addressing this is to:

  • convert our widget into a StatefulWidget (or rather, ConsumerStatefulWidget since we're using Riverpod)
  • add some local variables to keep track of state changes
  • set those variables inside calls to setState() to trigger a widget rebuild
  • use them to update the UI

Here's how the resulting code may look like:

For a simple app like this, this is probably ok.

But this approach gets quickly out of hand when we have more complex widgets, as we are mixing business logic and UI code in the same widget class.

And if we want to handle loading in error states consistently across multiple widgets, copy-pasting and tweaking the code above is quite error-prone (and not much fun).

Instead, it would be best to move all these concerns into a separate controller class that can:

  • mediate between our SignInScreen and the AuthRepository
  • provide a way for the widget to observe state changes and rebuild itself as a result

So let's see how to implement it in practice.

A controller class based on AsyncNotifier

The first step is to create a AsyncNotifier subclass which looks like this:

Or even better, we can use the new @riverpod syntax and let Riverpod Generator do the heavy lifting for us:

Either way, we need to implement a build method, which returns the initial value that should be used when the controller is first loaded.

If desired, we can use the build method to do some asynchronous initialization (such as loading some data from the network). But if the controller is "ready to go" as soon as it is created (just like in this case), we can leave the body empty and set the return type to Future<void> .

Implementing the method to sign in

Next up, let's add a method that we can use to sign in:

A few notes:

  • We obtain the authRepository by calling ref.read on the corresponding provider ( ref is a property of the base AsyncNotifier class)
  • Inside signInAnonymously() , we set the state to AsyncLoading so that the widget can show a loading UI
  • Then, we call AsyncValue.guard and await for the result (which will be either AsyncData or AsyncError )
AsyncValue.guard is a handy alternative to try / catch . For more info, read this: Use AsyncValue.guard rather than try/catch inside your StateNotifier subclasses

And as an extra tip, we can use a method tear-off to simplify our code even further:

This completes the implementation of our controller class, in just a few lines of code:

Note about the relationship between types

Note that there is a clear relationship between the return type of the build method and the type of the state property:

In fact, using AsyncValue<void> as the state allows us to represent three possible values:

  • default (not loading) as AsyncData (same as AsyncValue.data )
  • loading as AsyncLoading (same as AsyncValue.loading )
  • error as AsyncError (same as AsyncValue.error )
If you're not familiar with AsyncValue and its subclasses, read this: How to handle loading and error states with StateNotifier & AsyncValue in Flutter

Time to get back to our widget class and wire everything up!

Using our controller in the widget class

Here's an updated version of the SignInScreen that uses our new SignInScreenController class:

Note how in the build() method we watch our provider and rebuild the widget when the state changes.

And in the onPressed callback we read the provider's notifier and call signInAnonymously() . And we can also use the isLoading property to conditionally disable the button while sign-in is in progress.

We're almost done, and there's only one thing left to do.

Listening to state changes

Right at the top of the build method, we can add this:

We can use this code to call a listener callback whenever the state changes.

This is useful for showing an error alert or a SnackBar if an error occurs when signing in.

Bonus: An AsyncValue extension method

The listener code above is quite useful and we may want to reuse it in multiple widgets.

To do that, we can define this AsyncValue extension :

And then, in our widget, we can just import our extension and call this:

By implementing a custom controller class based on AsyncNotifier , we've separated our business logic from the UI code .

As a result, our widget class is now completely stateless and is only concerned with:

  • watching state changes and rebuilding as a result (with ref.watch )
  • responding to user input by calling methods in the controller (with ref.read )
  • listening to state changes and showing errors if something goes wrong (with ref.listen )

Meanwhile, the job of our controller is to:

  • talk to the repository on behalf of the widget
  • emit state changes as needed

And since the controller doesn't depend on any UI code, it can be easily unit tested , and this makes it an ideal place to store any widget-specific business logic.

In summary, widgets and controllers belong to the presentation layer in our app architecture:

But there are three additional layers: data , domain , and application , and you can learn about them here:

Or if you want to dive deeper, check out my Flutter Foundations course. 👇

Flutter Foundations Course Now Available

I launched a brand new course that covers Flutter app architecture in great depth, along with other important topics like state management, navigation & routing, testing, and much more:

Flutter Foundations Course

Flutter Foundations Course

Learn about State Management, App Architecture, Navigation, Testing, and much more by building a Flutter eCommerce app on iOS, Android, and web.

Invest in yourself with my high-quality Flutter courses.

Flutter & Firebase Masterclass

Flutter & Firebase Masterclass

Learn about Firebase Auth, Cloud Firestore, Cloud Functions, Stripe payments, and much more by building a full-stack eCommerce app with Flutter & Firebase.

The Complete Dart Developer Guide

The Complete Dart Developer Guide

Learn Dart Programming in depth. Includes: basic to advanced topics, exercises, and projects. Fully updated to Dart 2.15.

Flutter Animations Masterclass

Flutter Animations Masterclass

Master Flutter animations and build a completely custom habit tracking application.

Book cover

Oracle ADF Survival Guide pp 105–136 Cite as

Presentation Logic

  • Sten Vesterli 2  
  • First Online: 05 September 2017

673 Accesses

ADF handles all the basic functionality of getting data from the database onto the web page, accepting changes, and storing data back. But when you want to implement your own special way of handling the user interface, you need to start writing code. This chapter describes how to add logic to the presentation layer, using prebuilt UI component validators (declarative), managed beans (server-side Java code), and custom client-side JavaScript code

This is a preview of subscription content, log in via an institution .

Buying options

  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
  • Available as EPUB and PDF
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Author information

Authors and affiliations.

Værløse, Denmark

Sten Vesterli

You can also search for this author in PubMed   Google Scholar

Rights and permissions

Reprints and permissions

Copyright information

© 2017 Sten Vesterli

About this chapter

Cite this chapter.

Vesterli, S. (2017). Presentation Logic. In: Oracle ADF Survival Guide. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-2820-3_5

Download citation

DOI : https://doi.org/10.1007/978-1-4842-2820-3_5

Published : 05 September 2017

Publisher Name : Apress, Berkeley, CA

Print ISBN : 978-1-4842-2819-7

Online ISBN : 978-1-4842-2820-3

eBook Packages : Professional and Applied Computing Professional and Applied Computing (R0) Apress Access Books

Share this chapter

Anyone you share the following link with will be able to read this content:

Sorry, a shareable link is not currently available for this article.

Provided by the Springer Nature SharedIt content-sharing initiative

  • Publish with us

Policies and ethics

  • Find a journal
  • Track your research
  • Engineering Mathematics
  • Discrete Mathematics
  • Operating System
  • Computer Networks
  • Digital Logic and Design
  • C Programming
  • Data Structures
  • Theory of Computation
  • Compiler Design
  • Computer Org and Architecture
  • What is Report Generator?
  • Hardware RAID
  • Data-Access Layer
  • What is EII(Enterprise Information Integration)?
  • Measures of Query Cost in DBMS
  • Virtual Private Database (VPD)
  • Predicate Locking
  • Audit Trail
  • What is Software RAID?
  • Difference Between Hardware RAID vs Software RAID
  • ODBS Full Form
  • Strategies For Migrating From SQL to NoSQL Database
  • Introduction to NoSQL Cloud Database Services
  • Difference Between Data Mining and Data Analysis
  • Weak Levels of Consistency
  • Double Buffering
  • Access Types in DBMS
  • Failure Classification in DBMS
  • Query-Execution Plan in SQL

Business-Logic Layer

In this article, we are going to learn about the Business Logic Layer in Database Management systems. The Business Logic Layer also known as BLL act as an intermediate between the Presentation Layer and the Data Access Layer (DAL). This layer handles the business logic, business rules as well as calculations. It tells how the data from the database can be used, what it can perform, and what can not within its application.

The Business-Logic Layer (BLL) is a component of a software architecture that is responsible for implementing the business logic of an application. It sits between the presentation layer (e.g., the user interface) and the data access layer (e.g., the database), and is responsible for processing and manipulating data before it is presented to the user or stored in the database.

The BLL is responsible for performing tasks such as: -Validating input data to ensure that it meets the necessary business rules and constraints. -Performing calculations and transformations on data, as required by the business logic. -Enforcing business rules and policies, such as access control and security. -Communicating with the data access layer to retrieve and store data. -Handling errors and exceptions.

The BLL is designed to be reusable and independent of the user interface and data storage implementation. This allows the application to be easily modified or extended without affecting the underlying business logic.

The BLL is also responsible for managing the workflows and the use cases of the application, by handling the communication between the different layers, and by implementing the rules and constraints of the business.

In summary, The Business-Logic Layer (BLL) is a component of a software architecture that is responsible for implementing the business logic of an application. It sits between the presentation layer and the data access layer, and is responsible for processing and manipulating data before it is presented to the user or stored in the database. It also manages the workflows and the use cases of the application, and it is designed to be reusable and independent of the user interface and data storage implementation.

  • Presentation Layer: The layer at which users interact with the application and the final data will be visible to the users at this interface. It acts as an interface between the user and the application.
  • Business Logic Layer: It acts as an intermediate between the Presentation and the Data Access Layer.
  • Data Access Layer: The layer at which the data is managed.

Business Logic Layer

Business Logic Layer

  • All the three layers above play an important role in building an application
  • The business logic layer manages the communication between the database and the presentation layer.

Example: In an application, when the user access it or write queries in it with the help of a presentation or user interface layer the business logic layer helps the user to get a response to the asked queries by transferring it to the Data Access layer which further processes the query and give the suitable result to a business logic layer which is further transferred to the presentation layer which makes it visible to the user.

Due to the less clarity in defining the Business logic layer, some business domains like Microsoft and Apple excluded the BLL from their applications which leads to difficulty in code maintenance. A better approach is to build an application that supports multiple different user Interfaces.

Advantages of Business Logic Layer:

  • Code Maintenance is easy: Maintaining the code will be easy when we are using the Business Logical Layer as it supports multitier architecture. By using this we can easily determine any kind of change in the code.
  • Security: This architecture provides us the security as we can see that the Presentation layer doesn’t directly interact with the Data Access Layer which prevents it from any kind of data loss and ensures that the data is secure at the Data layer.
  • Application releases: It makes application release rollout easy. Because the Business Logic Layer is the only one to be updated every time then we do not need other layers of architecture i.e. the Presentation layer and the Data Access Layer.
  • Ease of learning: It is easy to learn because the learner has to specialize only in the presentation, data, and business layer to more quickly learn the specific parts of the application. The development time taken by the application will be small as all the layers can work together at the same time.

Disadvantages of Business Logic Layer:

  • Expensive: It will be very difficult and expensive to install and maintain this layer in databases.
  • Source control is very difficult to perform properly with existing procedures.
  • It makes it difficult to use the code, again and again, such that it decreases code reusability .

Applications of Business Logic Layer:

  • BLL has a major application in building multi-tier applications.
  • It is most commonly used in creating component-based applications.

Please Login to comment...

  • Computer Subject
  • 10 Best Chegg Alternatives in 2024
  • Devin AI: World’s First AI Software Engineer
  • 12 Best FlexClip Alternatives & Competitors in 2024 [Free + Paid]
  • What Is Trunk-Or-Treat?
  • 30 OOPs Interview Questions and Answers (2024)

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

COMMENTS

  1. What Is Three-Tier Architecture?

    The presentation tier and the data tier cannot communicate directly with one another. Tier versus layer. In discussions of three-tier architecture, layer is often used interchangeably - and mistakenly - for tier, as in 'presentation layer' or 'business logic layer'. They aren't the same.

  2. What is Presentation Logic? Complete Guide

    Presentation logic is the core of the application. The business logic layer provides a foundation for the user to interact with the application. It also contains all the business rules for the server. By contrast, presentation logic is the underlying code that determines how the data is presented. In contrast to business rules, presentation ...

  3. Presentation logic

    Presentation logic. In software development, presentation logic is concerned with how business objects are displayed to users of the software, e.g. the choice between a pop-up screen and a drop-down menu. [1] The separation of business logic from presentation logic is an important concern for software development and an instance of the ...

  4. Presentation Logic

    Presentation logic. An app's presentation logic is where almost all of the interaction with the end-user occurs. It is the part of the application that handles receiving inputs from the end-user and presenting the application's output to the end-user. ... The results are fed to the presentation layer. The data management tier, aka database ...

  5. Architectural Overview

    Application Architecture Concepts. Tweet. The data access layer consists of the definitions of database tables and columns and the computer logic that is needed to navigate the database. The layer in the application architecture enforces rules regarding the storage and access of information. For example: All date fields must be valid dates.

  6. Web Application Architecture: How the Web Works

    The two main distinctions enterprise application architecture has from a regular web application is the addition of another layer to the classic pattern - the service layer. The service layer is another abstraction between Presentation and Business Logic. It's an integration gateway that allows other software to access your business logic and ...

  7. 1. Layered Architecture

    For example, components in the presentation layer deal only with presentation logic, whereas components residing in the business layer deal only with business logic. This type of component classification makes it easy to build effective roles and responsibility models into your architecture, and also makes it easy to develop, test, govern, and ...

  8. Presentation Layer in OSI model

    Prerequisite : OSI Model Introduction : Presentation Layer is the 6th layer in the Open System Interconnection (OSI) model. This layer is also known as Translation layer, as this layer serves as a data translator for the network. The data which this layer receives from the Application Layer is extracted and manipulated here as per the required format to transmit over the network.

  9. What is presentation layer?

    The presentation layer is located at Layer 6 of the OSI model. The tool that manages Hypertext Transfer Protocol ( HTTP) is an example of a program that loosely adheres to the presentation layer of OSI. Although it's technically considered an application-layer protocol per the TCP/IP model, HTTP includes presentation layer services within it.

  10. Organizing Presentation Logic

    One of the most useful things you can do when designing any presentation layer is to enforce Separated Presentation. Once you've done this, the next step is to think about how the presentation logic itself is going to be organized. For a simple window, a single class may well suffice. But more complex logic leads to a wider range of breakdowns ...

  11. Presentation Domain Data Layering

    Martin Fowler. One of the most common ways to modularize an information-rich program is to separate it into three broad layers: presentation (UI), domain logic (aka business logic), and data access. So you often see web applications divided into a web layer that knows about handling HTTP requests and rendering HTML, a business logic layer that ...

  12. Layered Architecture: Building Scalable & Maintainable Software Systems

    The Spring framework uses a four-layered architecture that includes a presentation layer, a business logic layer, a persistence layer, and a data access layer. This layered approach has made it easier for developers to build scalable, robust, and flexible web applications that can handle large volumes of traffic and complex business logic. ...

  13. Multitier architecture

    In simple terms, it is a layer that users can access directly (such as a web page, or an operating system's GUI). Application tier (business logic, logic tier, or middle tier) The logical tier is pulled out from the presentation tier and, as its layer, it controls an application's functionality by performing detailed processing. Data tier

  14. Chapter 10

    Overview. The presentation layer contains the components that implement and display the user interface and manage user interaction. This layer includes controls for user input and display, in addition to components that organize user interaction. Figure 1 shows how the presentation layer fits into a common application architecture.

  15. N-Tier Architecture Presentation Logic Layer

    N-Tier Architecture Presentation Logic Layer. The Presentation Layer in an N-Tier structure is commonly referred to as the "client" layer. It consists of parts that are used to present data to an end user. Examples of components on the Presentation Layer might include edit boxes, labels, text boxes, grids, buttons, Windows or Web forms, or ...

  16. Understanding the Three Layers of APIs: Presentation, Business Logic

    2. Business Logic Layer. The business logic layer, also known as the "API middleware," is the layer that contains the core logic of the API. It is responsible for processing the requests received from the presentation layer and generating responses based on the requested actions. The business logic layer is where the API's core functionality ...

  17. PPTX PRESENTATION LAYER

    Typical components in the presentation layer. User Interface components: These are the application's visual elements used to display information to the user and accept user input. Presentation Logic components: Presentation logic is the application code that defines the logical behavior and structure of the application in a way that is independent of any specific user interface implementation.

  18. architecture

    The Presentation layer should only house presentation logic. Avoid Smart UIs that know too much. This mainly houses the MVC's Controllers and views in addition to CSS, JS, templates, forms and everything that relates to response and request objects. The actions issued through presentation are delegated to the application layer through commands.

  19. Flutter App Architecture: The Presentation Layer

    Flutter App Architecture: The Domain Model. Flutter App Architecture: The Application Layer. And this time, we will focus on the presentation layer and learn how we can use controllers to: hold business logic. manage the widget state. interact with repositories in the data layer. This kind of controller is the same as the view model that you ...

  20. Presentation Logic

    This chapter describes how to add logic to the presentation layer, using prebuilt UI component validators (declarative), managed beans (server-side Java code), and custom client-side JavaScript code. Download chapter PDF. As you saw in Chapter 1, ADF handles all the basic functionality of getting data from the database onto the web page ...

  21. design patterns

    Presentation logic would be a part of the user-facing tiers (desktop GUIs, web pages, mobile device screens). Most of the application logic would be in what's on both pictures marked as "Tier 2". ... Since MVC is a GUI pattern (some might call it GUI architecture, but it doesn't really matter), most of it is about the presentation layer, and ...

  22. Business-Logic Layer

    The Business-Logic Layer (BLL) is a component of a software architecture that is responsible for implementing the business logic of an application. It sits between the presentation layer (e.g., the user interface) and the data access layer (e.g., the database), and is responsible for processing and manipulating data before it is presented to ...

  23. Separation of presentation and logic

    The best place to set these colors is in the presentation layer using business rules. You can do it in the "business logic" but this means sending a ton of extra information to the presentation layer -- about presentation; either way you are breaking the "rule".

  24. Packt+

    C++ Programming for Linux Systems. This book covers the essential system programming tools and helps you explore the features of C++20. It emphasizes important details to maintain code quality and tackle everyday challenges of developing software for high performance, optimization, and more. Book Sep 2023 288 pages.