Presentation

An application has at least two components: business and presentation. The business component is responsible for business logic and data. This is the same as the model component of the MVC architecture.

The presentation component is the user interface (UI). It is responsible for receiving and executing commands from the user (controls), and then displaying the results (views).

An application may have zero, one, or many user interfaces:

Note that the user interface depends on the business component (model), but not vice-versa. Thus, user interfaces can be swapped or modified without modifying the business logic.

There are two main types of user interfaces: console user interfaces (cui) and graphical user interfaces (gui).

CUIs

A console user interface is a simple control loop of the form:

while(true) {
   prompt user for a command;
   read command;
   if (command == "quit") break;
   result = execute(command);
   display result;
}

This is also called a read-evaluate-print loop (REPL) or a shell.

A simple Java CUI.

A simple C++ CUI.

GUIs

A graphical user interface combines the Composite design pattern with the Master-Slave design pattern.

A GUI consists of a desktop window containing many GUI components such as buttons, text fields, and sub-windows. Examples of sub-windows includes menu bars, tool bars, dialog boxes, menus, and views (e.g., pie charts, bar graphs, text windows, etc.).

 

The master thread perpetually listens for user commands in the form of button clicks, menu selections, etc. When a command is received, a slave thread is launched to execute the command while the master thread resumes listening for user commands (such as cancel the last command).

GUIs in Java

GUIs in C++ (MFC)