Chapter 2. Presentation model

 

This chapter covers

  • Representing UI concepts in code
  • Defining the presentation model
  • Representing user input
  • Scaling to complex scenarios

A model is a representation of something meaningful. It’s not necessarily something physical but something real: a business concept or an API that’s difficult to work with.

When we write object-oriented software, we create classes that make up this representation. We can create our representation so that when we use it we’re working in a natural human language, like English or Spanish or business jargon, instead of in programming language constructs like Booleans, meaningless strings, and integers.

When working with a user interface (UI) framework like ASP.NET MVC, the UI is the complex problem that we manage. It’s the data in a window, a form submission from a user, the options in a select list. Whereas model is an overloaded term in software, this chapter focuses on the presentation model—the model that represents the screen and user input of an application.

2.1. The M in MVC

Consider a screen that shows a table to the user, as shown in figure 2.1.

Figure 2.1. A table in our user interface

This table is the product of our software development. It deserves to exist as a first-class object in our system. This will allow us to intentionally create it and to maintain it after its initial development.

2.2. Delivering the presentation model

2.3. ViewData.Model

2.4. Representing user input

2.5. More complex models for both display and input

2.6. Summary