DOC PREVIEW
UMD CMSC 131 - Lecture 25: Design

This preview shows page 1-2-21-22 out of 22 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Lecture 25 Design Last time 1 Interfaces cont 2 Wrappers Today 1 Project 5 is due 10 31 at 11 pm 2 Program designs algorithms interfaces use cases 10 27 2006 CMSC 131 Fall 2006 Rance Cleaveland 2006 Univeristy of Maryland Project 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 automated CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 1 Conditional Expressions if else can be used to create conditional statements Java also has a conditional expression operation Form bexp exp1 exp2 Meaning If bexp evaluates to true then exp1 is evaluated otherwise exp2 is evaluated Example int x 0 int y x 0 x 1 x 2 System out println y 2 is printed Difference between if else bexp exp1 exp2 if else is for statements bexp exp1 exp2 is for expressions Can t e g say int y if x 0 x 1 else x 2 x 0 y x 1 y x 2 CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 2 Coding vs Software Design Coding 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 CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland High level Low level 3 Low Level Design Pseudo Code and Algorithms We have already talked about pseudo code as a design technique NOT English NOT a program Something in between Captures the logic flow of desired code Note that pseudo code could be translated into any programming language not just Java Pseudo code is used to represent algorithms stepby step solutions to problems Algorithms are often coded as single methods CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 4 Example Linear Search Recall findMin from last time Given a non empty array find the smallest element Algorithm used is called linear search In pseudo code set variable min to initial element of array for each subsequent element in array compare element to min if element is less than min assign its value to min The polymorphic findMin method is the Java code implementing linear search CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 5 findMin static Comparable findMin Comparable a Comparable min a 0 for int i 1 i a length i if a i compareTo min 0 min a i return min CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 6 Concerns at the Algorithmic Level of Design Correctness Does my algorithm correctly solve the problem Efficiency Is my algorithm fast enough for the job Clarity Is my algorithm understandable CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 7 Interfaces and Design Next level up the design hierarchy what methods should go in classes This information can be captured using interfaces These interfaces can also be used to identify opportunities for polymorphism reusable code CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 8 Example Casino Suppose we are writing a simple casino program Two games Roulette and Dice Roulette bets 1 36 Even Odd Dice bets 1 6 Casino Dice Roulette Rough structure of classes given to right CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 9 Designing a Casino Game Interface What methods should be in interface between Casino and Dice Roulette Methods should support a generic game driver in Casino class Methods should be common to both Dice Roulette What notions are common to Dice Roulette Players make types of bets Players bet a certain amount Players play against the house not each other There is either a payoff or a loss CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 10 Interface Game java public interface Game String getName String getValidBets boolean isValidBet String b void setBetAmount int amt void setBet String bet int play Name of game Types of bets Is bet valid Set bet amount Set bet type Play the game CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 11 Rules of Thumb Keep interfaces small Think carefully about operations needed between classes Use interfaces to support polymorphism and keep code size down CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 12 A Generic Game Method in Casino See play method in Casino java CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 13 Upper Levels of Software Design Where 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 design CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 14 System 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 System Chef owners waiters etc Restaurant CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 15 System 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 2006 Rance Cleaveland 2006 University of Maryland 16 Essential 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 2006 Rance Cleaveland 2006 University of Maryland 17 Specifying Desired Behavior with Use Cases Use case a description of an interaction of a user and the system Use cases include Prerequisites pre conditions What must hold for this use case to arise Possible actions and interactions What happens Effects post


View Full Document

UMD CMSC 131 - Lecture 25: Design

Documents in this Course
Set #3

Set #3

7 pages

Exam #1

Exam #1

6 pages

Exam #1

Exam #1

6 pages

Notes

Notes

124 pages

Notes

Notes

124 pages

Load more
Download Lecture 25: Design
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 25: Design and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 25: Design and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?