Computer Science
Model View Controller
Model View Controller (MVC) is a software design pattern that separates an application into three interconnected components: the model, the view, and the controller. The model represents the data and business logic, the view displays the data to the user, and the controller handles user input and updates the model and view accordingly. This separation of concerns allows for easier maintenance and scalability of the application.
Written by Perlego with AI-assistance
Related key terms
1 of 5
11 Key excerpts on "Model View Controller"
- No longer available |Learn more
Software Architecture with Spring 5.0
Design and architect highly scalable, robust, and high-performance Java applications
- René Enríquez, Alberto Salazar(Authors)
- 2018(Publication Date)
- Packt Publishing(Publisher)
"MVC was conceived as a general solution to the problem of users controlling a large and complex data set. The hardest part was to hit upon good names for the different architectural components. Model-View-editor was the first set. "– http://heim.ifi.uio.no/~trygver/themes/mvc/mvc-index.htmlOne of the biggest problems in computer science is related to naming things, which is why the original name was Model-View-Editor. It later evolved into MVC, as mentioned in the preceding link: "After long discussions, particularly with Adele Goldberg, we ended with the terms Model-View-Controller."MVC is a software architectural pattern that makes it possible to establish a clear separation between the domain objects of an application (where the business logic resides) and the elements that are used to build the UI.With this concept in mind, the isolation and separation of concerns between these parts are quite important. They also constitute the underlying principles to build applications using this pattern. In following sections, let's review how the business logic and presentation layer of an application fits within the MVC pattern.Passage contains an image
The Model (M)
Within this context, the Model represents the domain objects needed to express the business logic supporting the requirements inherent to the application. It's here that all of the use cases are represented as real-world abstractions and a well-defined API is made available to be consumed by any kind of delivery mechanism, such as the web.Regarding traditional applications, all of the logic to interact with a database or middleware is implemented in the Model. However, the Model (the M in MVC) should expose functionalities (in terms of the business) that are easy to understand. We should also avoid building anemic models that only allow for interacting with the database and are difficult to understand for the rest of the team working on the project.Once this part of the application has been coded, we should ideally be able to create any UI that allows the users to interact with the Model. Furthermore, since UIs can defer from each other (mobile, web, and desktop apps), the Model should be agnostic to all of them. - eBook - ePub
- Bill Evjen, Scott Hanselman, Devin Rader(Authors)
- 2010(Publication Date)
- Wrox(Publisher)
ASP.NET MVC 1.0 shipped as a downloadable add-on to Visual Studio 2008. Now in Visual Studio 2010, ASP.NET MVC 2 ships built-in. This chapter also covers some of the limitations of ASP.NET Web forms and how ASP.NET MVC attempts to release the developer from those limitations.DEFINING MODEL-VIEW-CONTROLLER Model-View-Controller (MVC) is an architectural pattern used to separate an application into three main aspects:The content of this chapter is adapted from Professional ASP.NET MVC 1.0 by Rob Conery, Scott Hanselman, Phil Haack, and Scott Guthrie (Wiley, 2009). For more in-depth coverage of this topic, we recommend you check out that book.- The Model: A set of classes that describes the data you’re working with as well as the business rules for how the data can be changed and manipulated
- The View: The application’s user interface (UI)
- The Controller: A set of classes that handles communication from the user, overall application flow, and application-specific logic
- The Models are the classes that represent the domain in which you are interested. These domain objects often encapsulate data stored in a database as well as code used to manipulate the data and enforce domain-specific business logic. With ASP.NET MVC, this is most likely a data access layer of some kind using a tool like LINQ to SQL, Entity Framework, or NHibernate, combined with custom code containing domain-specific logic.
- The View is a dynamically generated page. In ASP.NET MVC, you implement it via the System.Web .Mvc.ViewPage class, which inherits from System.Web.UI.Page .
- The Controller is a special class that manages the relationship between the View and Model. It talks to the Model, and it decides which View to render (if any). In ASP.NET MVC, this class is conventionally denoted by the suffix “Controller
- eBook - PDF
Essentials of Interactive Computer Graphics
Concepts and Implementation
- Kelvin Sung, Peter Shirley, Steven Baer(Authors)
- 2008(Publication Date)
- A K Peters/CRC Press(Publisher)
5 The Model-View-Controller Architecture This chapter discusses the implementation of interactive graphics applications based on the model-view-controller (MVC) software architecture. This chapter: • introduces the MVC software architecture for organizing interactive graph-ics application solution design; • describes an MVC-based solution for the ball-shooting program; • demonstrates the expandability of the MVC-based solution; • develops software abstractions and library support for the implementation of our MVC-based ball-shooting solution. After this chapter we should: • understand the technology-independent MVC architecture; • understand the process for designing interactive applications based on the MVC architecture; • understand the concepts and implementation of having multiple view-controller pairs. 109 110 5. The Model-View-Controller Architecture In terms of implementation, we should be able to: • understand the software abstraction and libraries developed; • understand how to utilize these resources in implementing MVC-based so-lutions; • critically evaluate these resources and identify alternate solutions. At this point we know the following. • The programming model. We understand that the event-driven program-ming model better supports developing solutions for user interactive appli-cations in shared windowing environments. • The GUI API. We understand the principles of working with modern GUI APIs, and we understand the mechanisms for registration of events and the coordination between the front-end GUI elements and back-end program-ming code. • The graphics API. We have gained some understanding and developed sufficient abstraction to begin simple drawing with graphics APIs. These represent the foundation concepts and technology know-how for imple-menting the ball-shooting program. - eBook - ePub
Software Engineering
A Methodical Approach, 2nd Edition
- Elvis C. Foster, Bradford A. Towle Jr., Elvis Foster, Bradford Towle Jr.(Authors)
- 2021(Publication Date)
- Auerbach Publications(Publisher)
Section 9.5 ), having enforced software development standards is a requisite for serious and successful software engineering. As stated earlier, MVC is a common framework for scripting languages, especially the soft-type languages that can be written in line with HTML. With the remarkable advance of Web technology, programmers have come to the realization that not having any restriction on where the code was placed, resulted in the proliferation of bad coding practice and unmanageable projects. This recognition has led to widespread acceptance of the MVC framework.Modularity: The MVC architecture provides natural modularity to your project. A major component of software engineering is trying to find the balance between modularized code and convenience. You may have seen a project that is monolithic, or one with redundant levels of inheritance serving any real purpose. The MVC takes the guesswork out––you get three major categories of code, and usually, the model is rarely touched after it is initially created. Use of the MVC framework therefore capitalizes on re-use without requiring an unwieldy inheritance tree. Because of this, any application built with an MVC framework can instantly be parallelized between three groups of developers. The database team can work on the model, a second team can work on the controller, and the user interface team can work on the views. The only thing that must be agreed upon is how the data will be interchanged between the three modules.25.4 Software Patterns
Software patterns (also called software design patterns) are similar to frameworks, providing a generic solution approach to a specific problem domain. However, software patterns are typically not implemented but serve as template algorithms for the programmer. Also, software patterns are usually much smaller in scope than frameworks, focusing on common coding problems in the specific domain of interest.As an aspiring or practicing software engineer, you may choose to develop your own software pattern. Formally speaking, a software pattern should be accompanied by the following five areas of documentation: - eBook - PDF
iPhone SDK 3 Programming
Advanced Mobile Development for Apple iPhone and iPod touch
- Maher Ali(Author)
- 2009(Publication Date)
- Wiley(Publisher)
7 View Controllers The Model View Controller (MVC) is a popular design pattern that is used in software construction to isolate the business logic from the graphical user interface. In MVC, a controller is used for the purpose of coordination between the model (where the business logic resides) and the view (where the user’s interactions occur). In this chapter, you learn about the available view controllers that are provided in the iPhone SDK. Although you can build iPhone applications without the use of these view controllers, you shouldn’t. As you will see in this chapter, view controllers greatly simplify your application. Section 7.1 provides a gentle introduction to view controllers by presenting a simple application with a single view controller. This application demonstrates important view controller concepts. In Section 7.2, we talk about tab bar controllers and how they can be used in the construction of radio interfaces. In Section 7.3, we talk about navigation controllers used primarily for presenting hierarchical information to the user. After that, Section 7.4 talks about modal view controllers and provides a detailed example showing their appropriate usage. Finally, we summarize the chapter in Section 7.5. 7.1 The Simplest View Controller In this section, we demonstrate the simplest view controller. The application is composed of a view, a view controller, and a data model. The application simply displays a message that describes the orientation of the device. The view asks the controller for the message string, and the controller consults the device orientation and retrieves the appropriate text from the data model. 7.1.1 The view controller Listing 7.1 shows the declaration of the view controller. The UIViewController is the base class for all view controllers. When creating a view controller, you either subclass this class or one of its subclasses. The data model is represented by three strings where each describes the orientation of the - eBook - PDF
.NET 7 Design Patterns In-Depth
Enhance code efficiency and maintainability with .NET Design Patterns (English Edition)
- Vahid Farahmandian(Author)
- 2023(Publication Date)
- BPB Publications(Publisher)
But usually, having a controller for one page will complicate the code. Most of what the controller does can be divided into two parts. Part 1) receiving the HTTP request and part 2) deciding what processing should be done for an incoming request. Therefore, it is better to separate these two parts from each other. In this regard, you can get help from Front Controller. Model View Controller Name: Model View Controller Classification: Web presentation design patterns Also known as: MVC Intent: Using this pattern, the design of user interface interactions is divided into three different roles, which are view, model, and controller: • Model: It is an object that provides some information about the domain. All the data and behaviors related to them are presented through the model. In an object-oriented approach, the model can be considered an object within the domain model. • View: Data can be displayed in the UI through this section. The only task of this section is to display information and manage user interactions. In web applications, this section usually includes HTML codes. • Controller: Through this section, the data is received from the view, placed in the model, and it causes the view to be updated accordingly. 334 .NET 7 Design Patterns In-Depth Motivation, Structure, Implementation, and Sample code: With the preceding explanation, UI can be considered a combination of view and controller. We are planning to design a login form, and we intend for the user to enter his/her page by entering his/her username and password and see his/her username and password next to his/her name. According to the preceding requirement, the model class can be considered as follows: public class LoginModel { public string UserName { get; set; } public string Password { get; set; } public string FullName { get; set; } } As you can see, the Model class has three properties for UserName, Password, and FullName. - eBook - ePub
An Atypical ASP.NET Core 5 Design Patterns Guide
A SOLID adventure into architectural principles, design patterns, .NET 5, and C#
- Carl-Hugo Marcotte(Author)
- 2020(Publication Date)
- Packt Publishing(Publisher)
view model .Goal
The goal of the View Model pattern is to create a model, specific to a view , decoupling the other parts of the software from the view. As a rule of thumb, you want each view to be strongly typed with its own view model class to make sure that views are not coupled with each other, thereby causing possible maintenance issues in the long run.View models allow developers to gather data in a particular format and send it to the view in another format that's better suited for the rendering of that specific view. That improves the application's testability, which in turn should increase the overall code quality and stability.Design
Here is a revised MVC workflow that supports view models:Figure 4.2 – MVC workflow with view models We can interpret Figure 4.2 as the following:- The user requests an HTTP resource (routed to an action of a controller).
- The controller reads or updates the model.
- The controller creates the view model (or uses a view model created elsewhere).
- The controller dispatches that data structure to the view for rendering.
- The view uses the view model to render the HTML page.
- That rendered page is sent to the user over HTTP.
- The browser displays the page like any other web page.
Project: View models (a list of students)
Context : We have to build a list of students. Each list item must display a student's name and the number of classes that student is registered in.Our graphic designers came up with the following Bootstrap 3 list with badges:Figure 4.3 – Students list with their number of classesTo keep things simple and to create our prototype, we load in-memory data through the StudentService class.It is important to remember that the view model must only contain the required information to display the view. The view model classes, located in StudentListViewModels.cs - eBook - PDF
Web Development Toolkit for Java Developers
Build dynamic, secure, and scalable web applications with Java (English Edition)
- Dr. Nirali Dabhi, Dr. Dharmendra Patel, Dr. Atul Patel, Dr. Nirali Dabhi, Dr. Dharmendra Patel, Dr. Atul Patel(Authors)
- 2023(Publication Date)
- BPB Publications(Publisher)
Thus, every layer in MVC is assigned with a unique responsibility. So, the view is for the look and feel and for positioning what the end user will actually see. The model supplies the data and business logic. The controller is actually the heart of MVC, as it deals with invoking the right view and deciding the navigational part in traversing the application. The controller has to coordinate with the model and view layers. Need for MVC The MVC architectural pattern is not directly related to web applications. In fact, it’s quite common in Smalltalk applications, which generally have nothing to do with the web. MVC is concerned with separating responsibilities in web applications. Allowing a JSP page to handle the responsibilities of receiving the request, executing some business logic, and then determining the next view to display can make for an unattractive JSP page, not to mention the maintenance and extensibility problems this entanglement causes. Application development and maintenance are much easier if the different components of a web application have clear and distinct responsibilities. The following list mentions the need for MVC pattern in an application: • Servlets are good at data processing: reading and checking data, communicating with databases, invoking business logic, and so on. JSP pages are good at presentation: building HTML to represent the results of requests. This chapter describes how to combine servlets and JSP pages to best make use of the strengths of each technology. • Servlets are great when your application requires a lot of real programming to accomplish its task. But generating HTML with servlets can be tedious and can yield a result that is hard to modify. That's where JSP comes in. It lets you separate much of the presentation from the dynamic content. That way, you can write the HTML in the normal manner, even using HTML-specific tools and putting your web content developers to work on your JSP documents. - eBook - ePub
- Carl-Hugo Marcotte, Abdelhamid Zebdi(Authors)
- 2022(Publication Date)
- Packt Publishing(Publisher)
Those reasons make it easier to reuse backend systems and share them with multiple user interfaces or other backends. For example, think of any mobile app you know; it probably has an iOS, Android, and web app to maintain. In that case, sharing part of the backend can be an excellent way to save time and money.Goal
In a web API, the objective of the MVC pattern is to separate displaying (serializing) an entity into three distinct components that interact with each other. Doing this helps have smaller pieces that are easier to maintain and test than big bloated ones that are very hard to test in isolation.Design
MVC divides the application into three distinct parts, where each has a single responsibility:- Model : The model is a data structure representing the domain that we are modeling.
- View : The view’s responsibility is to present a model to a user; in this case, the view is a serialized model.
- Controller : The controller is the key component of MVC. It plays the coordinator role between a request from a user to its response. The code of a controller should remain minimal and should not include complex logic or manipulation. The controller’s primary responsibility is to handle a request and dispatch a response. The controller is an HTTP bridge.
- Instead of sending HTML to the browser, the API outputs a serialized data structure.
- The client wants to consume the data instead of having a browser display it.
Based on this diagram, we are sending our model directly to the client. In most scenarios, we don’t want to do that, and instead, we want to send only the portion of the data we need in the format we want. We will be covering this next with the DTO pattern, but first, let’s dig into ASP.NET Core web APIs.Anatomy of ASP.NET Core web APIs
We use the default template to explore web APIs’ anatomy. To generate a new web API project, you can execute the dotnet new webapi - eBook - PDF
- Adam Freeman(Author)
- 2017(Publication Date)
- Apress(Publisher)
Be careful not to reform your entire development effort around a pattern, however, since wide-sweeping disruption usually causes productivity loses that undermine whatever outcome you were hoping the pattern would give. Patterns are flexible tools and not fixed rules, but not all developers understand the difference, and some become pattern zealots . These are the people who spend more time talking about the pattern than applying it to projects and consider any deviation from their interpretation of the pattern to be a serious crime. My advice is to simply ignore this kind of person because any kind of engagement will just suck the life out of you, and you’ll never be able to change their minds. Instead, just get on with some work and demonstrate how a flexible application of a pattern can produce good results through practical application and delivery. With this in mind, you will see that I follow the broad concepts of the MVC pattern in the examples in this book but that I adapt the pattern to demonstrate different features and techniques. And this is how I work in my own projects—embracing the parts of patterns that provide value and setting aside those that do not. Understanding Models Models—the M in MVC —contain the data that users work with. There are two broad types of model: view models , which represent just data passed from the component to the template, and domain models , which contain the data in a business domain, along with the operations, transformations, and rules for creating, storing, and manipulating that data, collectively referred to as the model logic . ■ Tip Many developers new to the MVC pattern get confused with the idea of including logic in the data model, believing that the goal of the MVC pattern is to separate data from logic. This is a misapprehension: The goal of the MVC framework is to divide up an application into three functional areas, each of which may contain both logic and data. - eBook - ePub
Software Designers in Action
A Human-Centric Look at Design Work
- Marian Petre, Andre Van Der Hoek, Marian Petre, Andre Van Der Hoek(Authors)
- 2013(Publication Date)
- Chapman and Hall/CRC(Publisher)
Figure 3.6 , the design space includes at least four alternatives for an overall system concept. All teams chose different global organizations, and—curiously—none chose a simulator explicitly.Both Teams AD and IN mentioned the MVC in discussion, but both used the MVC pattern informally and neither mentioned the MVC in the summary presentations. Team IN did not appear to use the MVC architecture to organize the model and controller. Team AD did refer to the model and controller; however, as noted above, instead of using the model–controller distinction to organize the design activity, they tried to map elements of their design into the MVC template. In classic MVC, the controller is chiefly a dynamic mediator between the user’s actions (through the UI) and the domain logic in the model. Here, especially for Team AD, the controller handled the details of running the simulation. When the simulation is running, the user is not (or at least not necessarily) offering input to the system. So, incorporating the simulation logic in the controller makes sense for the common informal meaning of “controller,” but it is not a good match for the controller of the MVC pattern.For several design decisions, different teams chose different alternatives, but in each case the team simply adopted the alternative rather than considering the choices. One such example is the model of time. Team AD decided (at 11:25–12:50, without considering alternatives) on a master clock that synchronized the simulation with regular “ticks.” This is one of the standard models for representing time in a simulation, the other being an event queue that sets off events in simulated time order; a third alternative is to design with parallel threads, which leaves the underlying time model to the implementation. The synchronous regular-tick time model is the better match for a visualization that should proceed smoothly (that is, with a uniform scale factor relative to real time), but that was not mentioned in the discussion. Team IN speculated about a clock at 38:12, but at 38:33 they described the simulation control as firing off a car thread for each input, and by 49:30 they had a massively parallel simulation. The teams did explicitly address the model for time, but they did not make deliberate choices; had a representation of the design space been available, they might have either made different decisions or developed confidence in the decisions they did make.
Index pages curate the most relevant extracts from our library of academic textbooks. They’ve been created using an in-house natural language model (NLM), each adding context and meaning to key research topics.










