CS 232 Project 1.5: User Interfaces and Reuseable Code

Overview: Good coding style separates a program's computation (aka its Model), its user-interface (aka its View), and its control code (aka its Controller), because doing so: (a) allows a program to support multiple user interfaces, and (b) maximizes the amount of reuseable code in the application. Software engineers know this as the MVC (Model-View-Controller) pattern. In this assignment, you will apply this pattern to your program. (See these two diagrams of a Simple MVC and Complex MVC. I don't know if these help or not...)


This project is to rewrite project 1 in a more object-oriented fashion. The trick is to write it in such a way that a maximal amount of your code is reuseable. To gauge this, you are to build two user interfaces for your program:

  1. a text-based command-line-switch-driven user interface (like we used in Assignment 1), plus
  2. either:
    1. a text-based menu-driven user interface, or
    2. a graphical user interface (your choice);
while minimizing redundant coding. Each interface will need its own controller class, containing the code to control that version of the application.

One way to approach this problem is to imagine yourself building two completely separate versions of your application, each providing a different user interface. A fair amount of those applications would be redundant code. In the MVC pattern, you "factor out" that common code into your Model class. You should also build classes for each different user interface (e.g., MenuView and its corresponding controller (e.g., MenuController). Your Controller classes can then create instances of their View classes, and an instance of your Model class to do the actual work.

Your driver program callTimer should be fairly simple:

  1. If any commandline arguments exist, create an instance of your CommandLineArgController class, passing it the command-line information (argc and argv).
    Otherwise, create an instance of your other controller class.
  2. Send the Controller you've created the run() message to get it to perform its task.

The Controller class(es) create(s) an instance of the Model class and View class. My code passes in the Controller object and Model object to the View (as well as argc and argv for CommandLineArgController).

The View class will parse command-line args or get the values from the user. It will then set these values in the Model (either directly or through calls to its Controller). It will also "register" itself with the Model class, so that when the Model has finished computing times for lauching processes/threads, the Model can call functions in the View object to display the results.

The run() method of the Controller sets values in the Model (if the values weren't set directly by the View), and then calls the Model's run() method.

If you find yourself writing redundant coding for the user-interfaces, store the redundant coding in a superclass, and derive your classes from this superclass.

Plan of Action.

1. Review your solution to Assignment 1. Then imagine yourself building two separate applications that do the same thing but using different user interfaces. Identify the functionality they would have in common, and design a Model class to provide that functionality.

2. Identify what information your Model class needs to receive in order to perform its computation, and the most efficient way for it to receive that information from an outside entity. Your Controller classes are going to need to communicate that information to your Model.

3. Decide which user interfaces you are going to provide. Design View and Controller classes for each one. Your Controller should create its View, use it to get the information it needs for the Model, and then pass that information to the Model.

4. Implement the Model, Controller and View classes, as well as any superclasses needed to isolate code common to these classes.

5. Rewrite your driver so that it checks for command-line args (if any), creates the appropriate Controller, and then sends it the run() message.

When your program is working, compare the results it produces to those of your previous version. (There should not be a significant difference.)

As before, you are free to talk to your classmates about algorithmic details, and general approaches you use in this project, provided you give proper credit in your documentation to ideas that are not your own. You are not to look at anyone else's code, for any reason.

Your program is to be carefully documented and readable, as described in the previous assignment.

Turn in:

Copy your source code to /home/cs/232/current/<yourid>/proj1.5/. Also, submit a script file, in which you demonstrate:

  1. gcc or g++ successfully compiling your program; and
  2. For each of your user-interfaces (views):
    Execute your program as many times as necessary to show that it works correctly for the various inputs (including invalid ones).
  3. The project grade sheet, in which you've put your Name.

Do not forget that your code will be inspected for compliance with the CS-232 Coding Standards.

Due date: Monday, Feb. 29, 11:59 p.m.

Calvin > CS > 232 > Projects > 1.5

This page maintained by Joel Adams.