CSC 309 Lecture Notes Week 2
General Design Principles and
High-Level Design Patterns
Details of Specification-to-Design Refinement
users.csc.calpoly.edu:~gfisher/classes/309/examples/milestone2
users.csc.calpoly.edu:~gfisher/classes/309/examples/misc-java
"Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use the solution a million times over, without ever doing it the same way twice."
Figure 1: MVP Pattern.
Figure 2: IPT pattern.
Figure 3: Calendar Tool packages.
package caltool.model;
import caltool.view.*;
import caltool.model.file.*;
import caltool.model.edit.*;
import caltool.model.schedule.*;
import caltool.model.view.*;
import caltool.model.admin.*;
import caltool.model.options.*;
import caltool.model.help.*;
import caltool.model.caldb.*;
import mvp.Model;
/****
*
* Class CalendarTool is the top-level model class for the regular-user
* Calendar Tool program. CalendarTool has references to the functional model
* classes of the tool: File, Edit, Schedule, View, Admin, Options, and Help.
* There is also a reference to the CalendarDB class that houses the tool's
* major data bases.
* <p>
* Functionalitywise, all of the model classes are autonomous units. They each
* do their own work as invoked by the user. All that this top-level class
* does is to construct the work-doing model classes and set up the initial
* state of the tool when it is invoked from the outside operating system.
* <p>
* See also the companion view class <a href= "caltool_ui/CalendarToolUI.html">
* CalendarToolUI. </a>
* <p>
* @author Gene Fisher (gfisher@calpoly.edu)
* @version 12Nov13
*
*/
public class CalendarTool extends Model {
/**
* Construct this with the given companion view. Call the submodel
* constructors. Initialize the start-up state based on default options
* and command-line arguments.
*/
public CalendarTool(CalendarToolUI calToolUI) {
/*
* Call the parent constructor.
*/
super(calToolUI);
/*
* Construct and store the submodel instances. Note that the
* CalendarDB is constructed before the File so the latter can observe
* the former for changes.
*/
caldb = new CalendarDB(null);
file = new File(null, caldb);
edit = new Edit(null);
schedule = new Schedule(null, caldb);
calView = new View(null, caldb);
admin = new Admin(null);
options = new Options(null);
/*
* Set up the initial state of the tool.
*/
initialize();
}
/**
* Implement the exit method to pass the buck to file.exit(). Per set up
* performed in the companion CalendarToolUI view, this method is called
* when the user closes the top-level menubar window, e.g., via the window
* manager close button.
*/
public void exit() {
file.exit();
}
/** Return the File model. */
public File getFile() { return file; }
/** Return the Edit model. */
public Edit getEdit() { return edit; }
/** Return the Schedule model. */
public Schedule getSchedule() { return schedule; }
/** Return the View model. */
public View getCalView() { return calView; }
/** Return the Admin model. */
public Admin getAdmin() { return admin; }
/** Return the Options model. */
public Options getOptions() { return options; }
/** Return the Help model. */
public Help getHelp() { return help; }
/*-*
* Protected methods
*/
/**
* Set up the initial state of the tool, based on default option values and
* command-line arguments, if any. Details TBD.
*/
void initialize() {}
/*-*
* Data fields
*/
/** File-handling module */
protected File file;
/** Basic editing module */
protected Edit edit;
/** Scheduling module */
protected Schedule schedule;
/** Calendar viewing module */
protected View calView;
/** Calendar administration module */
protected Admin admin;
/** Tool options module */
protected Options options;
/** Tool help module */
protected Help help;
/** Calendar database */
protected CalendarDB caldb;
}
Figure 4: Class diagram for Calendar Tool design in Notes 2.
users.csc.calpoly.edu:~gfisher/classes/309/examples/milestone2
users.csc.calpoly.edu:~gfisher/classes/308/examples/milestone6/specification
users.csc.calpoly.edu:~gfisher/classes/308/examples/milestone8/prototype
Figure 5: Annotated menus showing swing components used.
Figure 6: Annotated dialog showing swing components used.
Figure 7: Annotated dialog showing layout using boxes.
| Suffix | Example | Meaning |
| UI | ScheduleUI | A top-level view that contains all of the interface components for a companion top-level model. These components are the pulldown command menu and all of the other views that are launched from menu commands. |
| Dialog | ScheduleAppointmentDialog | A top-level view that allows the user to provide inputs for a single operation. Typically it has OK, Cancel, and Clear buttons. The OK button is used to confirm the operation for which the user is entering the input. |
| Editor | CategoriesEditor | A top-level view that provides for the editing Has more command buttons than just OK, e.g., Add, Delete. |
| Display | MonthlyAgendaDisplay | A read-only display, i.e., where no model data are editable. |
| ButtonListener | OKScheduleAppointmentButtonListener | An event listener for a button or menu item. |
| Panel | SchedulingOptionsPanel | The internal component of a tiled or tabbed layout. |
Figure 8: High-level Model/View class diagram.
Figure 9: Highest-level function diagram for Model/View application.
Figure 10: Event diagramming notation.
Figure 11: Setting up Calendar Tool event handlers.
Figure 12: Responding to Calendar Tool GUI events.