CSCI 383 Object-Oriented Programming & Design Lecture 8 Martin van Bommel.
-
Upload
stephanie-watts -
Category
Documents
-
view
216 -
download
0
Transcript of CSCI 383 Object-Oriented Programming & Design Lecture 8 Martin van Bommel.
CSCI 383
Object-Oriented Programming & Design
Lecture 8
Martin van Bommel
Fall 2010 CSCI 383 Lecture 8 M. van Bommel 2
Intelligent Interactive Kitchen Helper
Imagine you are the chief software architect in a major computing firm
One day your boss rushes into your office with a specification for the next PC-based product. It is drawn on the back of a used dinner napkin, in handwriting that appears to be that of your boss
Briefly, the Intelligent Interactive Kitchen Helper will replace the box of index cards of recipes in the average kitchen
Fall 2010 CSCI 383 Lecture 8 M. van Bommel 3
Your Job
Your job is to develop the software that will implement the IIKH
Fall 2010 CSCI 383 Lecture 8 M. van Bommel 4
Abilities of the IIKH
Here are some of the things a user can do with the IIKH [identified as a result of a use-case analysis]: Browse a database of recipes Add a new recipe to the database Edit or annotate an existing recipe Scale a recipe for some number of diners Plan a meal consisting of several courses Plan a longer period, say a week Generate a grocery list that includes all the items in
all the menus for a period
Fall 2010 CSCI 383 Lecture 8 M. van Bommel 5
Scenarios
A scenario is an instance of a use case It expresses a specific occurrence of the use case
A specific actor ... At a specific time ... With specific data
Can be part of the Description field of a use case
Fall 2010 CSCI 383 Lecture 8 M. van Bommel 6
An Example Scenario
Alice Smith sits down at her computer and starts the IIKH. When the program begins, it displays a graphical image of a recipe box and identifies itself as the IIKH, product of IIKH incorporated. Alice presses the return button to begin.
Fall 2010 CSCI 383 Lecture 8 M. van Bommel 7
An Example Scenario (cont’d)
In response to the key press, Alice is given a choice of a number of options. She elects to browse the recipe index, looking for a recipe for salmon that she wishes to prepare for dinner the next day. She enters the keyword “salmon” and is shown in response a list of various recipes.
Alice remembers seeing an interesting recipe that used dill weed as seasoning. She refines the search, adding the phrase “dill weed”.
This narrows the search to two recipes.
Fall 2010 CSCI 383 Lecture 8 M. van Bommel 8
An Example Scenario (cont’d)Alice selects the first. This brings up a new window in which an attractive picture of the finished dish is displayed, along with the list of ingredients, preparation steps, and expected preparation time.
After examining the recipe, Alice determines it is not the recipe she wanted. She returns to the search result page and selects the second alternative.
Examining this dish, Alice decides this is the one she had in mind. She requests a printout of the recipe, and the output is spooled to her printer. Alice selects “quit” from a program menu, and the application quits.
Fall 2010 CSCI 383 Lecture 8 M. van Bommel 9
Software Components
A software component is simply an abstract design entity with which we can associate responsibilities for different tasks
May eventually be turned into a class, a function, a module, or something else
A component must have a small well defined set of responsibilities
A component should interact with other components to the minimal extent possible
Fall 2010 CSCI 383 Lecture 8 M. van Bommel 10
CRC Cards
Components are most easily described using CRC cards. A CRC card records the name, responsibilities, and collaborators of a component
Inexpensive, Erasable, Physical
Fall 2010 CSCI 383 Lecture 8 M. van Bommel 11
CRC Cards (cont’d) Responsibilities
Express responsibilities as short verb phrases containing active rather than passive verbs
Define what should be done, not how to do it (declarative)
Include only essential information, not a great deal of detail
Collaborators A collaborator for a class or object is another class or
object with which the first class communicates to carry out its responsibilities
The sender of a message usually is not one of the collaborators of the receiver
Fall 2010 CSCI 383 Lecture 8 M. van Bommel 12
CRC Cards (cont’d) Identify an initial set of classes and objects. Can
be done by performing a “grammatical parse” on scenarios or use case descriptions. Create one card for each
Identify an initial set of responsibilities and collaborators for each card. This may lead to the identification of other classes and objects
Spread the cards out on a desk, attach them to a wall, or, for a group project, assign one or more cards to each person in the group
Run through usage scenarios; as the flow of control passes to an object or class, bring that card to a prominent spot
As the scenarios are played out, gaps in the design are filled in. This is a form of iterative refinement
Fall 2010 CSCI 383 Lecture 8 M. van Bommel 13
A Component, The Greeter
Let us return to the development of the IIKH. The first component your team defines is the Greeter. When the application is started, the Greeter puts an informative and friendly welcome window (the greeting) on the screen
Fall 2010 CSCI 383 Lecture 8 M. van Bommel 14
A Component, The Greeter (cont’d)
Offer the user the choice of several different actions Casually browse the database of recipes Add a new recipe Edit or annotate a recipe Review a plan for several meals Create a plan of meals
Many of the details concerning exactly how this is to be done can be ignored for the moment
Fall 2010 CSCI 383 Lecture 8 M. van Bommel 15
A Component, The Greeter (cont’d)
CRC card?
Fall 2010 CSCI 383 Lecture 8 M. van Bommel 16
The Recipe Database Component
Ignoring the planning of meals for the moment, your team elects to next explore the recipe database component Must Maintain the Database of recipes Must Allow the user to browse the database Must permit the user to add a new recipe Must permit the user to edit or annotate an existing
recipe
Fall 2010 CSCI 383 Lecture 8 M. van Bommel 17
The Who/What Cycle
As we walk through scenarios, we go through cycles of identifying a what, followed by a who What action needs to be performed at this moment, Who is the component charged with performing the
action
Every what must have a who, otherwise it simply will not happen.
Sometimes the who might not be obvious at first, i.e., who should be in charge of editing a recipe?
Fall 2010 CSCI 383 Lecture 8 M. van Bommel 18
Postponing Decisions
Many decisions, such as the method of browsing, can be ignored for the moment, as they are entirely encapsulated within the recipe database component, and do not effect other components Scroll bars and windows? A virtual “book” with thumb-holes and flipping pages? Keywords and phrases?
Only need to note that somehow the user can manipulate the database to select a specific recipe
Fall 2010 CSCI 383 Lecture 8 M. van Bommel 19
Responsibilities of a Recipe
We make the recipe itself into an active data structure. It maintains information, but also performs tasks Maintains the list of ingredients and transformation
algorithm Must know how to edit these data values Must know how to interactively display itself on the
output device Must know how to print itself We will add other actions later (ability to scale itself,
produce integrate ingredients into a grocery list, and so on)
Fall 2010 CSCI 383 Lecture 8 M. van Bommel 20
The Planner Component
Returning to the greeter, we start a different scenario. This leads to the description of the Planner Permits the user to select a sequence of dates for
planning Permits the user to edit an existing plan Associates with Date object
Fall 2010 CSCI 383 Lecture 8 M. van Bommel 21
The Date Component
The Date component holds a sequence of meals for an individual date User can edit specific meals User can annotate information about dates
(“Bob's Birthday”, “Christmas Dinner”, and so on) Can print out grocery list for entire set of meals
Fall 2010 CSCI 383 Lecture 8 M. van Bommel 22
The Meal component holds information about a single meal Allows user to interact with the recipe database to
select individual recipes for meals User sets number of people to be present at meal,
recipes are automatically scaled Can produce grocery list for entire meal, by
combining grocery lists from individual scaled recipes
The Meal Component
Fall 2010 CSCI 383 Lecture 8 M. van Bommel 23
The Six Components
Having walked through the various scenarios, you team eventually decides everything can be accomplished using only six software components
You can at this point assign the different components to different programmers for development
Fall 2010 CSCI 383 Lecture 8 M. van Bommel 24
Interaction Diagrams
The picture on the previous slide captures static relationships, but not the dynamic flow of messages in a scenario. That information can be recorded by an interaction diagram