Chapter 2: Programming Architecture 2.1 Model View Controller (MVC)
Chapter 2: Programming Architecture 2.1 Model View Controller (MVC)
Programming
Technology
BECE
4th
Semester
The Architecture
In a MVC application as having three main layers: presentation (UI), application logic, and
resource management. In MVC, the presentation layer is split into controller and view. The most
important separation is between presentation and application logic. The View/Controller split is less
so. MVC encompasses more of the architecture of an application than is typical for a design pattern.
Hence the term architectural pattern may be useful, or perhaps an aggregate design pattern.
Though MVC comes in different flavours, the control flow generally works as follows:
1. The user interacts with the user interface in some way (e.g., user presses a button)
2. A controller handles the input event from the user interface, often via a registered handler or
callback.
3. The controller accesses the model, possibly updating it in a way appropriate to the user’s
action (e.g., controller updates user’s shopping cart). Complex controllers are often
structured using the command pattern to encapsulate actions and simplify extension.
4. A view uses the model to generate an appropriate user interface (e.g., view produces a
screen listing the shopping cart contents). The view gets its own data from the model. The
model has no direct knowledge of the view. (However, the observer pattern can be used to
allow the model to indirectly notify interested parties, potentially including views, of a
change.)
5. The user interface waits for further user interactions, which begins the cycle anew.
Early computer system can best be described as monolithic system in which all processing occurred
on the same machine. User interacted with the monolithic system through dumb terminal. It is
desirable to move away from such monolithic system and divide the work between several different
computers- this change signaled the birth of client/server systems.
The client–server model is a distributed application structure in computing that partitions tasks or
workloads between the providers of a resource or service, called servers, and service requesters,
called clients. Often clients and servers communicate over a computer network on separate
hardware, but both client and server may reside in the same system. A server is a host that is
running one or more server programs which share their resources with clients. A client does not
share any of its resources, but requests a server's content or service function. Clients therefore
initiate communication sessions with servers that await incoming requests.
Types of Server
There are two types of servers you can have:
1. Iterative Server: This is the simplest form of server where a server process serves one
client and after completing first request then it takes request from another client. Meanwhile
another client keeps waiting.
2. Concurrent Servers: This type of server runs multiple concurrent processes to serve many
request at a time. Because one process may take longer and another client cannot wait for so
long.
Performance: Performance:
• Adequate performance for low to medium • Inadequate performance for medium to
volume environments high volume environments, since
• Business logic and database are database server is required to perform
physically close, which provides higher business logic. This slows down database
performance. operations on database server.
Fat-Client/Fat-Server: Client does most of the processing. User Interface and all data
processing/Business logic are done on client. The Data Service Layer is the actual Database Server,
which handles the storage or services the data. Note that this will be the architecture we will use to
create our class projects.
Thin-Client/Fat-Server: Client has less processing, usually UI & UI-Centric Business Objects. The
Data-Centric Business Objects, which handles the data access code, resides on the Data Service
Layer or Database Server.
Middle tier is also called as business logic tier or service tired. In the simple client-server solution
the client was handling the business logic and that makes the client “thick”. A thick client means
that it requires heavy traffic with the server, thus making it difficult to use over slower network
connections like Internet and Wireless (LTE, 3G, or Wi-Fi).
By introducing the middle layer, the client is only handling presentation logic. This means that only
little communication is needed between the client and the middle tier making the client “thin” or
“thinner”. An example of a thin client is an Internet browser that allows you to see and provide
information fast and almost with no delay.
As more users access the system a three-tier solution is more scalable than the other solutions
because we can add as many middle tiers (running on each own server) as needed to ensure good
performance (N-tier or multiple-tier). Security is also the best in the three-tier architecture because
the middle layer protects the database tier. There is one major drawback to the N-tier architecture
and that is that the additional tiers increase the complexity and cost of the installation.
However, the MVC architecture is triangular: the view sends updates to the controller, the
controller updates the model, and the view gets updated directly from the model.
2. History: From a historical perspective the three-tier architecture concept emerged in the
1990s from observations of distributed systems (e.g., web applications) where the client,
middleware and data tiers ran on physically separate platforms.
Whereas MVC comes from the previous decade (by work at Xerox PARC in the late 1970s
and early 1980s) and is based on observations of applications that ran on a single graphical
workstation; MVC was applied to distributed applications later in its history.
Today, MVC and similar model-view-presenter (MVP) are Separation of Concerns design patterns
that apply exclusively to the presentation layer of a larger system. In simple scenarios MVC may
represent the primary design of a system, reaching directly into the database; however, in most
scenarios the Controller and Model in MVC have a loose dependency on either a Service or Data
layer/tier. This is all about Client-Server architecture in the 3-tier equivalent, communication
between layers is bi-directional and always passes through the Middle tier in the MVC equivalent
the communication is in unidirectional; we could say that each "layer" is updated by the one at the
left and, in turn, updates the one at the right –where "left" and "right" are merely illustrative