0% found this document useful (0 votes)
27 views11 pages

Unit 5 ME

The Model-View-Controller (MVC) framework is an architectural pattern that separates applications into three components: Model, View, and Controller, allowing for clearer organization and maintainability. MVC is widely used in web and mobile app development, facilitating Test Driven Development (TDD) and enhancing scalability. It offers advantages such as easy maintenance and independent testing of components, but can also introduce complexity and inefficiencies in data access.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views11 pages

Unit 5 ME

The Model-View-Controller (MVC) framework is an architectural pattern that separates applications into three components: Model, View, and Controller, allowing for clearer organization and maintainability. MVC is widely used in web and mobile app development, facilitating Test Driven Development (TDD) and enhancing scalability. It offers advantages such as easy maintenance and independent testing of components, but can also introduce complexity and inefficiencies in data access.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

What is MVC?

The Model-View-Controller (MVC) framework is an architectural/design pattern that separates an


application into three main logical components Model, View, and Controller. Each architectural
component is built to handle specific development aspects of an application. It isolates the business
logic and presentation layer from each other. It was traditionally used for desktop graphical user
interfaces (GUIs). Nowadays, MVC is one of the most frequently used industry-standard web
development frameworks to create scalable and extensible projects. It is also used for designing
mobile apps.

MVC was created by Trygve Reenskaug. The main goal of this design pattern was to solve the
problem of users controlling a large and complex data set by splitting a large application into specific
sections that all have their own purpose.

Features of MVC

 It provides a clear separation of business logic, UI logic, and input logic.

 It offers full control over your HTML and URLs which makes it easy to design web application
architecture.

 It is a powerful URL-mapping component using which we can build applications that have
comprehensible and searchable URLs.

 It supports Test Driven Development (TDD).

To know more about the benefits of using the MVC Framework refer to the article – Benefits of using
MVC framework

Components of MVC

The MVC framework includes the following 3 components:

 Controller

 Model

 View
Controller:

The controller is the component that enables the interconnection between the views and the model
so it acts as an intermediary. The controller doesn’t have to worry about handling data logic, it just
tells the model what to do. It processes all the business logic and incoming requests, manipulates
data using the Model component, and interact with the View to render the final output.

Responsibilities:

 Receiving user input and interpreting it.

 Updating the Model based on user actions.

 Selecting and displaying the appropriate View.

Example: In a bookstore application, the Controller would handle actions such as searching for a
book, adding a book to the cart, or checking out.

View:

The View component is used for all the UI logic of the application. It generates a user interface for
the user. Views are created by the data which is collected by the model component but these data
aren’t taken directly but through the controller. It only interacts with the controller.

Responsibilities:

 Rendering data to the user in a specific format.

 Displaying the user interface elements.

 Updating the display when the Model changes.


Example: In a bookstore application, the View would display the list of books, book details, and
provide input fields for searching or filtering books.

Model:

The Model component corresponds to all the data-related logic that the user works with. This can
represent either the data that is being transferred between the View and Controller components or
any other business logic-related data. It can add or retrieve data from the database. It responds to
the controller’s request because the controller can’t interact with the database by itself. The model
interacts with the database and gives the required data back to the controller.

Responsibilities:

 Managing data: CRUD (Create, Read, Update, Delete) operations.

 Enforcing business rules.

 Notifying the View and Controller of state changes.

Example: In a bookstore application, the Model would handle data related to books, such as the
book title, author, price, and stock level.

Working of the MVC framework with Example

Let’s imagine an end-user sends a request to a server to get a list of students studying in a class. The
server would then send that request to that particular controller that handles students. That
controller would then request the model that handles students to return a list of all students
studying in a class.

The flow of Data in MVC Components


The model would query the database for the list of all students and then return that list back to the
controller. If the response back from the model was successful, then the controller would ask the
view associated with students to return a presentation of the list of students. This view would take
the list of students from the controller and render the list into HTML that can be used by the
browser.

The controller would then take that presentation and returns it back to the user. Thus ending the
request. If earlier the model returned an error, the controller would handle that error by asking the
view that handles errors to render a presentation for that particular error. That error presentation
would then be returned to the user instead of the student list presentation.

As we can see from the above example, the model handles all of the data. The view handles all of the
presentations and the controller just tells the model and view of what to do. This is the basic
architecture and working of the MVC framework.

The MVC architectural pattern allows us to adhere to the following design principles:
1. Divide and conquer. The three components can be somewhat independently designed.
2. Increase cohesion. The components have stronger layer cohesion than if the view and controller
were together in a single UI layer.
3. Reduce coupling. The communication channels between the three components are minimal and
easy to find.
4. Increase reuse. The view and controller normally make extensive use of reusable components for
various kinds of UI controls. The UI, however, will become application-specific, therefore it will not be
easily reusable.
5. Design for flexibility. It is usually quite easy to change the UI by changing the view, the controller,
or both.

Advantages of MVC

 Codes are easy to maintain and they can be extended easily.

 The MVC model component can be tested separately.

 The components of MVC can be developed simultaneously.

 It reduces complexity by dividing an application into three units. Model, view, and controller.

 It supports Test Driven Development (TDD).

 It works well for Web apps that are supported by large teams of web designers and
developers.

 This architecture helps to test components independently as all classes and objects are
independent of each other

 Search Engine Optimization (SEO) Friendly.

Disadvantages of MVC

 It is difficult to read, change, test, and reuse this model

 It is not suitable for building small applications.

 The inefficiency of data access in view.


 The framework navigation can be complex as it introduces new layers of abstraction which
requires users to adapt to the decomposition criteria of MVC.

 Increased complexity and Inefficiency of data

Popular MVC Frameworks

Some of the most popular and extensively used MVC frameworks are listed below.

 Ruby on Rails

 Django

 CherryPy

 Spring MVC

 Catalyst

 Rails

 Zend Framework

 Fuel PHP

 Laravel

 Symphony

MVC is generally used on applications that run on a single graphical workstation. The division of
logical components enables readability and modularity as well as it makes it more comfortable for
the testing part.

3-tier Application Architecture


In software development, it’s very common to see applications built with a specific architectural
paradigm in mind. One of the most prevalent patterns seen in modern software architecture is the 3-
tier (or three-tier) architecture. This model structures an application into three distinct tiers:
presentation (user interface), logic(business logic), and data (data storage).

The fundamental advantage of 3-tier architecture lies in the clear separation of concerns. Each tier
operates independently, allowing developers to focus on specific aspects of the application without
affecting other layers. This enhances maintainability, as updates or changes can be made to a single
tier with minimal impact on the others. 3-tier applications are also highly scalable since each tier can
be scaled horizontally or vertically to handle increased demand as usage grows.

This post delves into the fundamentals of 3-tier applications. In it, We’ll cover:

 The concept of 3-tier architecture: What it is and why it’s important.

 The role of each tier: Detailed explanations of the presentation, application, and data tiers.

 How the three tiers interact: The flow of data and communication within a 3-tier application.
 Real-world examples: Practical illustrations of how 3-tier architecture is used.

 Benefits of this approach: Advantages for developers, architects, and end-users.

With the agenda set, let’s precisely define the three tiers of the architecture in greater detail.

What is a 3-tier application architecture?

A 3-tier application is a model that divides an application into three interconnected layers:

 Presentation Tier: The user interface where the end-user interacts with the system (e.g., a
web browser or a mobile app).

 Logic Tier: The middle tier of the architecture, also known as the logic tier, handles the
application’s core processing, business rules, and calculations.

 Data Tier: Manages the storage, retrieval, and manipulation of the application’s data,
typically utilizing a database.

This layered separation offers several key advantages that we will explore in more depth later in the
post, but first, let’s examine them at a high level.

First, it allows for scalability since each tier can be scaled independently to meet changing
performance demands. Second, 3-tier applications are highly flexible; tiers can be updated or
replaced with newer technologies without disrupting the entire application. Third, maintainability is
enhanced, as modifications to one tier often have minimal or no effect on other tiers. Finally, a
layered architecture allows for improved security, as multiple layers of protection can be
implemented to safeguard sensitive data and business logic.

How does a 3-tier application architecture work?


The fundamental principle of a 3-tier application is the flow of information and requests through the
tiers. Depending on the technologies you use, each layer has mechanisms that allow each part of the
architecture to communicate with the other adjacent layer. Here’s a simplified breakdown:

1. User Interaction: The user interacts with the presentation tier (e.g., enters data into a web
form or clicks a button on a mobile app).

2. Request Processing: The presentation tier sends the user’s request to the application tier.

3. Business Logic: The logic tier executes the relevant business logic, processes the data, and
potentially interacts with the data tier to retrieve or store information.

4. Data Access: If necessary, the application tier communicates with the data tier to access the
database, either reading data to be processed or writing data for storage.

5. Response: The logic tier formulates a response based on the processed data and business
rules and packages it into the expected format the presentation tier requires.

6. Display: The presentation tier receives the response from the application tier and displays
the information to the user (e.g., updates a webpage or renders a result in a mobile app).

The important part is that the user never directly interacts with the logic or data tiers. All user
interactions with the application occur through the presentation tier. The same goes for each
adjacent layer in the 3-tier application. For example, the presentation layer communicates with the
logic layer but never directly with the data layer. To understand how this compares to other n-tier
architectural styles, let’s take a look at a brief comparison.

1-tier vs 2-tier vs 3-tier applications

While 3-tier architecture is a popular and well-structured approach, it’s not the only way to build
applications. As time has passed, architecture has evolved to contain more layers. Some approaches
are still used, especially in legacy applications. Here’s a brief comparison of 1-tier, 2-tier, and 3-tier
architectures:

 1-tier architecture (Monolithic):

o All application components (presentation, logic, and data) reside within a single
program or unit.

o Simpler to develop initially, particularly for small-scale applications.

o It becomes increasingly difficult to maintain and scale as complexity grows.

 2-tier architecture (Client-Server Applications):

o Divides the application into two parts: the client (presentation/graphical user
interface) and a server, which typically handles both logic and data.

o Offers some modularity and improved scalability compared to 1-tier.

o Can still face scalability challenges for complex systems, as the server tier combines
business logic and data access, potentially creating a bottleneck.

 3-tier architecture:
o Separates the application into presentation, application (business logic), and data
tiers.

o Provides the greatest level of separation, promoting scalability, maintainability, and


flexibility.

o Typically requires more development overhead compared to simpler architectures.

The choice of architecture and physical computing tiers that your architecture uses depends on your
application’s size, complexity, and scalability requirements. Using a multi-tier architecture tends to be
the most popular approach, whether client-server architecture or 3-tier. That being said, monolithic
applications still exist and have their place.

The logical tiers of a 3-tier application architecture

The three tiers at the heart of a 3-tier architecture are not simply physical divisions; they also
represent a separation in technologies used. Let’s look at each tier in closer detail:

1. Presentation tier

 Focus: User interaction and display of information.

 Role: This is the interface that users see and interact with. It gathers input, formats and
sanitizes data, and displays the results returned from the other tiers.

 Technologies:

o Web Development: HTML, CSS/SCSS/Sass, TypeScript/JavaScript, front-end


frameworks (React, Angular, Vue.js), a web server.

o Mobile Development: Platform-specific technologies (Swift, Kotlin, etc.).

o Desktop Applications: Platform-specific UI libraries or third-party cross-platform


development tools.

2. Logic tier

 Focus: Core functionality and business logic.

 Role: This tier is the brain of the application. It processes data, implements business rules
and logic, further validates input, and coordinates interactions between the presentation and
data tiers.

 Technologies:

o Programming Languages: Java, Python, JavaScript, C#, Ruby, etc.

o Web Frameworks: Spring, Django, Ruby on Rails, etc.

o App Server/Web Server

3. Data tier

 Focus: Persistent storage and management of data.

 Role: This tier reliably stores the application’s data and handles all access requests. It
protects data integrity and ensures consistency.
 Technologies:

o Database servers: Relational (MySQL, PostgreSQL, Microsoft SQL Server) or NoSQL


(MongoDB, Cassandra).

o Database Management Systems: Provide tools to create, access, and manage data.

o Storage providers (AWS S3, Azure Blobs, etc)

Separating concerns among these tiers enhances the software’s modularity. This makes updating,
maintaining, or replacing specific components easier without breaking the whole application.

3-tier application examples

Whether a desktop or web app, 3-tier applications come in many forms across almost every industry.
Here are a few relatable examples of how a 3-tier architecture can be used and a breakdown of what
each layer would be responsible for within the system.

E-commerce websites

 Presentation Layer: The online storefront with product catalogs, shopping carts, and
checkout interfaces.

 Logic Layer: Handles searching, order processing, inventory management, interfacing with
3rd-party payment vendors, and business rules like discounts and promotions.

 Data Layer: Stores product information, customer data, order history, and financial
transactions in a database.

Content management systems (CMS)

 Presentation Layer: The administrative dashboard and the public-facing website.

 LogicLayer: Manages content creation, editing, publishing, and the website’s structure and
logic based on rules, permissions, schedules, and configuration

 Data Layer: Stores articles, media files, user information, and website settings.

Customer relationship management (CRM) systems

 Presentation Layer: Web or mobile interfaces for sales and support teams.

 Logic Layer: Processes customer data, tracks interactions, manages sales pipelines, and
automates marketing campaigns.

 Data Layer: Maintains a database server with data for customers, contacts, sales
opportunities, and support cases.

Online booking platforms (e.g., hotels, flights, appointments)

 Presentation Layer: Search features, promotional materials, and reservation interfaces.

 Logic Layer: Handles availability checks, real-time pricing, booking logic, and payment
processing to 3rd-party payment vendors.

 Data Layer: Stores schedules, reservations, inventory information, and customer details.
Of course, these are just a few simplified examples of a 3-tier architecture in action. Many of the
applications we use daily will use a 3-tier architecture (or potentially more tiers for a modern web-
based application), so finding further examples is generally not much of a stretch. The examples
above demonstrate how application functionality can be divided into one of the three tiers.

Benefits of a 3-tier app architecture

One of the benefits of the 3-tier architecture is it’s usually quite apparent why using it would be
advantageous over other options, such as a two-tier architecture. However, let’s briefly summarize
the advantages and benefits for developers, architects, and end-users who will build or utilize the 3-
tier architecture pattern.

Scalability

Each tier can be independently scaled to handle increased load or demand. For example, you can add
more servers to the logic tier to improve processing capabilities without affecting the user
experience or add more database servers to improve query performance.

Maintainability

Changes to one tier often have minimal impact on the others, making it easier to modify, update, or
debug specific application components. As long as contracts between the layers (such as API
definitions or data mappings) don’t change, developers can benefit from shorter development cycles
and reduced risk.

Flexibility

You can upgrade or replace technologies within individual tiers without overhauling the entire
system. This allows for greater adaptability as requirements evolve. For example, if the technology
you are using within your data tier does not support a particular feature you need, you can replace
that technology while leaving the application and presentation layers untouched, as long as contracts
between the layers don’t change (just as above).

Improved Security

Multiple layers of security can be implemented across tiers. This also isolates the sensitive data layer
behind the logic layer, reducing potential attack surfaces. For instance, you can have the logic layer
enforce field-level validation on a form and sanitize the data that comes through. This allows for two
checks on the data, preventing security issues such as SQL injection and others listed in the OWASP
Top 10.

Reusability

Components within the logic tier can sometimes be reused in other applications, promoting
efficiency and code standardization. For example, a mobile application, a web application, and a
desktop application may all leverage the same application layer and corresponding data layer. If the
logic layer is exposed externally through a REST API or similar technology, it also opens up the
possibility of leveraging this functionality for third-party developers to take advantage of the API and
the underlying functionality.

Developer specialization

Teams can specialize in specific tiers (e.g., front-end, back-end, database), optimizing their skills and
improving development efficiency. Although many developers these days focus on full-stack
development, larger organizations still divide teams based on frontend and backend technologies.
Implementing a 3-tier architecture fits well with this paradigm of splitting up responsibilities.

The benefits listed above cover multiple angles, from staffing and infrastructure to security and
beyond. The potential upside of leveraging 3-tier architectures is wide-reaching and broadly
applicable. It leaves no question as to why 3-tier architectures have become the standard for almost
all modern applications. That being said, many times, the current implementation of an application
can be improved, and if an application is currently undergoing modernization, how do you ensure
that it will meet your target and future state architecture roadmap? This is where vFunction can
swoop in and help.

How vFunction can help with modernizing 3-tier applications

vFunction offers powerful tools to aid architects and developers in streamlining the modernization of
3-tier applications and addressing their potential weaknesses. Here’s how it empowers architects and
developers:

Architectural observability

vFunction provides deep insights into your application’s architecture, tracking critical events like new
dependencies, domain changes, and increasing complexity over time. This visibility allows you to
pinpoint areas for proactive optimization and the creation of modular business domains as you
continue to work on the application.

You might also like