+ All Categories
Home > Documents > CSCI-383 Object-Oriented Programming & Design Lecture 7.

CSCI-383 Object-Oriented Programming & Design Lecture 7.

Date post: 19-Jan-2016
Category:
Upload: louisa-walker
View: 218 times
Download: 0 times
Share this document with a friend
25
CSCI-383 Object-Oriented Programming & Design Lecture 7
Transcript
Page 1: CSCI-383 Object-Oriented Programming & Design Lecture 7.

CSCI-383

Object-Oriented Programming & Design

Lecture 7

Page 2: CSCI-383 Object-Oriented Programming & Design Lecture 7.

Example of generalization, extension and inclusion

Example: Use-case diagram for a home security system

Page 3: CSCI-383 Object-Oriented Programming & Design Lecture 7.

Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd

An Example, the IIKH 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 your boss’s

Briefly, the Intelligent Interactive Kitchen Helper will replace the box of index cards of recipes in the average kitchen

Page 4: CSCI-383 Object-Oriented Programming & Design Lecture 7.

Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd

Your Job

Your job is to develop the software that will implement the IIKH

Page 5: CSCI-383 Object-Oriented Programming & Design Lecture 7.

Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd

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 Plan a meal consisting of several courses Scale a recipe for some number of users Plan a longer period, say a week Generate a grocery list that includes all the items in

all the menus for a period

Page 6: CSCI-383 Object-Oriented Programming & Design Lecture 7.

Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd

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

Page 7: CSCI-383 Object-Oriented Programming & Design Lecture 7.

Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd

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.

Page 8: CSCI-383 Object-Oriented Programming & Design Lecture 7.

Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd

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. She remembers seeing an interesting recipe that used dill weed as seasoning. She refines the search, entering the words “salmon” and “dill weed”. This narrows the search to two recipes.

Page 9: CSCI-383 Object-Oriented Programming & Design Lecture 7.

Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd

An Example Scenario (cont’d)

She 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.

Page 10: CSCI-383 Object-Oriented Programming & Design Lecture 7.

Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd

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

Page 11: CSCI-383 Object-Oriented Programming & Design Lecture 7.

Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd

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

Page 12: CSCI-383 Object-Oriented Programming & Design Lecture 7.

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

Page 13: CSCI-383 Object-Oriented Programming & Design Lecture 7.

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 or attach them to a wall

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

Page 14: CSCI-383 Object-Oriented Programming & Design Lecture 7.

Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd

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

Page 15: CSCI-383 Object-Oriented Programming & Design Lecture 7.

Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd

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

Page 16: CSCI-383 Object-Oriented Programming & Design Lecture 7.

Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd

A Component, The Greeter (cont’d)

CRC card?

Page 17: CSCI-383 Object-Oriented Programming & Design Lecture 7.

Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd

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 edit or annotate an existing

recipe Must permit the user to add a new recipe

Page 18: CSCI-383 Object-Oriented Programming & Design Lecture 7.

Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd

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?

Page 19: CSCI-383 Object-Oriented Programming & Design Lecture 7.

Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd

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

Page 20: CSCI-383 Object-Oriented Programming & Design Lecture 7.

Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd

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)

Page 21: CSCI-383 Object-Oriented Programming & Design Lecture 7.

Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd

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

Page 22: CSCI-383 Object-Oriented Programming & Design Lecture 7.

Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd

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

Page 23: CSCI-383 Object-Oriented Programming & Design Lecture 7.

Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd

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

Page 24: CSCI-383 Object-Oriented Programming & Design Lecture 7.

Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd

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

Page 25: CSCI-383 Object-Oriented Programming & Design Lecture 7.

Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd

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


Recommended