full document
abstractBACKGROUNDoverviewprelabinlab

Winning it BIG in the Lottery
Background


Over the years experienced programmers tend to use the same techniques to solve similar problems. Only recently have attempts been made to catalog some of the more common approaches to these problems. These approaches are commonly referred to as design patterns. A design pattern names and explains important and recurring designs in object-oriented systems. One such pattern, that is commonly used in Graphical User Interfaces (GUI), is the model-view-controller (MVC) design pattern. In this pattern, the program is logically divided into three objects: model, view, and the controller. The model is the application, the view provides a visual representation of the model, and the controller defines the way the user interface reacts to user input. The MVC pattern is illustrated in Figure 1.


Figure 1

The main motivation for the MVC pattern is to separate the logic of the program from its view. In this way, if someone decides to change the graphical user interface, the only component that needs to be modified is the view. It is also possible to have multiple views that use the same model.

In this lab, you will be working with a program that consists of four classes: Lotto, LottoGUI, LottoLogic, and BallBox. The LottoGUI class does the work of the view and the controller from the MVC model, and LottoLogic does the work of the model. BallBox is a class that provides the ability to generate a stream of random numbers. Figure 2 illustrates how these classes interact to make up the Lotto program. For those of you who are interested in building simple GUI based applications, LottoGUI contains most of the basic code that you will need to develop a GUI on your own.


Figure 2 Figure 2

Programs that use graphical interfaces are not controlled in the same way as a standard program. The part of the program that is in control is the GUI. The GUI generates events that trigger the appropriate action within a model. For example in the lotto program, when the GUI senses that a user has pressed a numbered button, it will call the buttonPressed() method in a LottoLogic object. So the Lotto program does not determine when buttonPressed() is invoked, the user does. The Lotto program is driven by events external to the program as opposed to by logic within the main program. This type of programming is referred to as event-driven programming.

The LottoLogic class contains three methods that are meant to be called by the GUI in response to external events. These methods are: draw, reset, and buttonPressed. Your task in this lab is to complete these three


Copyright RIT 2003
$Id: writeup.xml,v 1.6 2003/10/07 18:43:37 cs1 Exp $