RPG Academy: UI Modernization, Part 3—Introducing the MVC

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Time to introduce a conceptual (but rather useful) new tool for your arsenal: the MVC. No, it’s not a new type of vehicle! It’s the model-view-controller model.

The multi-tier architecture implementations shown in the previous TechTip are a step in the right direction, but they have its limitations:

  • You’re still bound by the DDS limits—Your UIs will still be text-based and limited to a 24x80 or 27x132 green-screen resolution.
  • Your code is not truly separated—Code for screen handling and control flow is still intertwined. It’s true that this approach makes it much easier to maintain, but you still have some code that is not where it should be. This also means that your “UI expert” also has to be the “control flow expert,” when these can be different tasks.

As you can see, this is not a perfect solution. It can work in a lot of situations, but to truly modernize your UI, for instance via a graphical user interface (GUI), you need to completely isolate it from the rest of the code. One proven way to do that is to apply the model-view-controller (MVC) paradigm to your IBM i application. Historically, developers, particularly developers of object-oriented languages, have used the MVC paradigm to implement clear divisions between various components of an application. The term components here refers to the more general definition, not exactly a module, but a group of code pieces of the same type: UI (presentation), processing (business rules enforcement and so on), and data access. The function of most applications is to retrieve data from a database and display it to the user, allowing the user to interact with the data and store updates in the database.

The MVC pattern was developed, as many other great things in IT, by Smalltalk programmers trying to determine the best way to couple event-driven UI objects with the classes that represent the state of the business model. This pattern was adopted by the Java community and incorporated into the Java Swing classes. Many other languages came up with their own implementation of the MVC, such as Microsoft’s ASP.NET MVC, for example.

In today’s fast-paced business world, UIs change much more frequently than the database portions of applications. While this is true for an IBM i-only application, it is even more true in a Web-connected application. Coupling the data and UI of a business application tends to require business logic that goes far beyond the application’s data transmission (or view). Following good design principles pays off when it comes time to make changes to an application’s structure, as you usually do in a modernization initiative. Web services and design paradigms such as the MVC, shown in Figure 1, go a long way in developing and maintaining applications that are feature-rich and capable of handling dynamic content, while supporting a rapid development model to match the business needs.

RPG Academy: UI Modernization, Part 3—Introducing the MVC - Figure 1 

Figure 1: The MVC design pattern (adapted from Sun Microsystem’s original model)

The MVC design pattern splits a program into three layers:

  • The model provides the business logic and data access capabilities of the application and exposes business services.
  • The view displays and collects information from users.
  • The controller intercepts input and translates it into actions performed by the model. In other words, it controls the main flow of the program.

The MVC is somewhat similar to the multi-tier model, but it separates the data access layer from the interface so that the view (i.e., the UI) can be easily replaced or expanded. In the MVC, changes to the model data are reflected in all interfaces, because all views are observers of the data. However, you can change the view (or presentation layer) without any impact to the other two layers. This design pattern also helps ease the maintenance burden by ensuring that changes to the business logic layer are less likely to break the presentation layer, and conversely, that changes to the presentation layer are less likely to break the business logic.

Where the modular approach allowed several RPG programmers to work on different parts (modules) of the same program, the MVC approach facilitates multi-disciplined team development. Developers can focus on creating robust business code without having to worry about breaking the UI, and designers can focus on building useful and engaging UIs without worrying about the language their colleagues are using to develop the business code. As I said before, the “UI experts” don’t need to know RPG at all; they just need to have ways to access the data. The MVC approach facilitates the use of the best tools for each aspect of the development process, such as using RPG for creating the business logic and a combination of HTML, CSS, and JavaScript for creating the UI.

As this is probably new for some readers, it’ll require some additional explanations for the concept of MVC to really sink in and become something useful. Over the next few TechTips, I’ll be talking about each of the layers and how to reengineer an ILE program using the MVC.

Until then, feel free to comment, using the Comments section below.

Rafael Victoria-Pereira

Rafael Victória-Pereira has more than 20 years of IBM i experience as a programmer, analyst, and manager. Over that period, he has been an active voice in the IBM i community, encouraging and helping programmers transition to ILE and free-format RPG. Rafael has written more than 100 technical articles about topics ranging from interfaces (the topic for his first book, Flexible Input, Dazzling Output with IBM i) to modern RPG and SQL in his popular RPG Academy and SQL 101 series on mcpressonline.com and in his books Evolve Your RPG Coding and SQL for IBM i: A Database Modernization Guide. Rafael writes in an easy-to-read, practical style that is highly popular with his audience of IBM technology professionals.

Rafael is the Deputy IT Director - Infrastructures and Services at the Luis Simões Group in Portugal. His areas of expertise include programming in the IBM i native languages (RPG, CL, and DB2 SQL) and in "modern" programming languages, such as Java, C#, and Python, as well as project management and consultancy.


MC Press books written by Rafael Victória-Pereira available now on the MC Press Bookstore.

Evolve Your RPG Coding: Move from OPM to ILE...and Beyond Evolve Your RPG Coding: Move from OPM to ILE...and Beyond
Transition to modern RPG programming with this step-by-step guide through ILE and free-format RPG, SQL, and modernization techniques.
List Price $79.95

Now On Sale

Flexible Input, Dazzling Output with IBM i Flexible Input, Dazzling Output with IBM i
Uncover easier, more flexible ways to get data into your system, plus some methods for exporting and presenting the vital business data it contains.
List Price $79.95

Now On Sale

SQL for IBM i: A Database Modernization Guide SQL for IBM i: A Database Modernization Guide
Learn how to use SQL’s capabilities to modernize and enhance your IBM i database.
List Price $79.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: