10/30/2006 CMSC 131 Fall 2006Rance Cleaveland©2006 Univeristy of MarylandLecture 26:DesignLast time:1. Basics of program design2. Algorithms3. Interfaces4. Software design and system designToday:1. System design2. Use cases3. Command-line JavaCMSC 131 Fall 2006Rance Cleaveland©2006 University of Maryland1Project #5 Assigned! Project due Tuesday, 10/31 at 11 pm Project is closed You must complete the project by yourself Assistance can only be provided by teaching assistants (TAs) and instructors You must not look at other students' code Start now! Read entire assignment from beginning to end before starting to code Check out assignment now from CVS Follow the instructions exactly, as much of grading is automatedCMSC 131 Fall 2006Rance Cleaveland©2006 University of Maryland2Recall from Last Lecture:Coding vs. Software DesignCoding: writing of (Java) code to implement classes, methods, etc. Projects so far have been primarily coding We have told you what to code Design: determination of what to code What classes are needed? How should classes interact? What methods belong in each class? How should method functionality be implemented?High-levelLow-levelCMSC 131 Fall 2006Rance Cleaveland©2006 University of Maryland3Recall from Last Lecture:Upper Levels of Software DesignWhere do ideas for classes, interactions between classes come from? Software development part of larger system design process System design requires identifying what system users expect system to do These user requirements often suggest system components and how they fit together First part of software design: understand system designCMSC 131 Fall 2006Rance Cleaveland©2006 University of Maryland4System Design: What Is It? System design is concerned with: coordinating a collection of entities… … to achieve a complex process Each entity has its own responsibilities to the others to achieve an overall objective E.g. Restaurant Entities Chef, owners, waiters, etc. System RestaurantCMSC 131 Fall 2006Rance Cleaveland©2006 University of Maryland5System Examples Classroom environment: Lecturers, TAs, students, … Library: Circulation (checkout and return), indexing services (online catalogue), library users, book buyers, shelvers, … Pharmacy: Patients (and medical records), pharmacists, doctors, drug retailers, the pharmacy (products in stock), … Video game: Race cars, motorcycles, warriors, space ships, death squads, monsters, aliens, mutants, guns, swords, weapons of mass destruction, cute Japanese cartoon animals with huge eyes, …CMSC 131 Fall 2006Rance Cleaveland©2006 University of Maryland6Essential Questions What is the desired behavior of the program (as a whole)? What are the entities that produce this behavior? How does each one work? How do these entities interact?CMSC 131 Fall 2006Rance Cleaveland©2006 University of Maryland7Specifying Desired Behavior with Use CasesUse case: a description of an interaction of a user and the system. Usecases include: Prerequisites (pre-conditions)What must hold for this use case to arise? Possible actions and interactionsWhat happens? Effects (post-conditions)What conditions hold, what changes have taken place, as a result of these actions. Example: Customer in a restaurant Pre-conditions: Customer: hungry and has moneyRestaurant: is open Actions: get menu, order food, be served, eat, pay, leave Post-conditions: Customer: full, less moneyRestaurant: more money, less foodCMSC 131 Fall 2006Rance Cleaveland©2006 University of Maryland8Principal Design Elements Components What are the entities that make up our system? What are the roles they play? How do we separate the system into distinct units? Contract What are the responsibilities and services associated with each component? What guarantees does it make? StateWhat is the current status/state of the units that define our system? InteractionUse casesCMSC 131 Fall 2006Rance Cleaveland©2006 University of Maryland9Example: Pharmacy Store SystemComponentsPharmacist, customers, doctors, prescription, store stock, … Contract Pharmacists can fill prescriptions Doctors write prescriptions Pharmacists only fill the prescriptions written by doctors Pharmacists and doctors maintain patient records etc. State (patient)Current prescriptions, number of times refilled, date of last refill, health insurance information Fill prescription use case: A valid prescription presented by the customer Pharmacists checks patient records and informs of possible side-effects Pharmacist dispenses prescription Patient records updated Medication given to patientCMSC 131 Fall 2006Rance Cleaveland©2006 University of Maryland10Relationship to Java System: A Java program Components: Java classes and objects State: Object instance variables, class static variables Contract: API / interface The external (class user) view of an object Provides an abstraction of what the object does, without indicating how it is implemented Includes prototypes of actions (methods) The contract is implemented using methodsCMSC 131 Fall 2006Rance Cleaveland©2006 University of Maryland11Command-Line Java So far we have been using Eclipse to Create Run Debug TestJava programs Is Eclipse the only way to write Java? No! Any text editor can be used to create Java code Java can be compiled and executed from the “command line” (= DOS prompt = Unix shell = etc.)CMSC 131 Fall 2006Rance Cleaveland©2006 University of Maryland12Creating Java Programs with a Text EditorYou can use any text editor: Wordpad Notepad Emacs vi etc. Be sure the file is saved as “plain text” (= ASCII) The name of the file must be Foo.java if the name of the class being defined is FooCMSC 131 Fall 2006Rance Cleaveland©2006 University of Maryland13Compiling Java Outside Eclipse The Java compiler creates bytecode from Java source code If the source file is Foo.java … … the bytecode is contained in Foo.class How to execute the compiler outside of Eclipse? Start a command window Execute command javac Foo.java This creates Foo.class Note: the operating system must be able to find javac! My machine: c:\Program Files\Java\jdk1.5.0_08\bin Windows use the notion of path = list of
View Full Document