+ All Categories
Home > Documents > CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to:...

CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to:...

Date post: 18-Jan-2016
Category:
Upload: philomena-cobb
View: 215 times
Download: 0 times
Share this document with a friend
Popular Tags:
60
CS 1410 Object Oriented Design
Transcript
Page 1: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

CS 1410Object Oriented Design

Page 2: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

ObjectivesAt the end of this lesson, students should be able to:• Describe the software life cycle. • Given a computing problem, create a use case diagram that illustrates the use cases for that problem. • Given a use case, create a storyboard that illustrate the steps involved in that use case. • Use a storyboard to discover the classes and member functions required to solve a computing problem. • Create a CRC card for a class, and explain the terms cohesion and coupling. • Create UML class diagrams and sequence diagrams. • Write function prologues that contain properly stated pre- and post-conditions for a function. • Correctly write assertions in your code to test pre- and post-conditions.

Page 3: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

You will be expected to use the skillslearned in this lesson throughout the

rest of the semester.

Page 4: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

“The transformation from a set of requirements and vague notions of what is desired to a structured plan of the building and what actions are required to build it is the creative activity of new development”

Ivar Jacobson

Page 5: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

“The distinguishing characteristic of industrial strengthsoftware is that it is intensely difficult, if not impossible,for the individual developer to comprehend all of thesubtleties of its design. Stated in blunt terms, thecomplexity of modern software systems exceeds thehuman intellectual capacity.”

Grady Booch

Page 6: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Some Software Failures:

In 1992, a woman received an invitation to attend a kindergarten.The woman was 104 years old.

A supermarket was fined $1000 for having meat around 1 day toolong on February 29, 1988. The computer program responsible for printing the expiration label did not take into account that 1988 wasa leap year.

In 1995, bugs in the automated luggage system in Denver’s newInternational airport caused suitcases to be chewed up. Because ofthis the airport opened 16 months late and $3.2 Million over budget.

After 18 months of development, a $200 million system was delivered to a health insurance company in Wisconsin in 1984. However, the systemdid not work correctly. $60 million in overpayments were made by mistake.It took 3 years to fix.

The C-17 cargo plane by McDonnell Douglas ran $500 million over budget because of problems with the avionics software.

Page 7: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

The Problem Software is getting more complex Software development costs are going up Software development time is getting longer software maintenance costs are going up Software errors are getting more frequent

Many of these problems can be addressed by using awell defined development process.

Page 8: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Four phases of An Iterative Development Process

Elaboration

Inception

Construction

Transition

Page 9: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Inception

Develop a vision of the end product– What will the product do for its users?– What will customers pay for this function?– How will the product be developed?

What are the requirements?– If we build it, they won’t necessarily come!– How do we know what to build? – use

cases!

Page 10: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Elaboration

Use cases are specified in detail Over-all Architecture is developed Detailed business plan is developed Detailed development plan is developed Contract made

Page 11: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Construction

Product is developed End product must satisfy the use cases agreed to with the customer Code may still contain defects Beta code made available – test with

customers

Page 12: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Transition

From development to shipped code Rigorous testing and customer use Delivery system established Support system established Maintenance system established

Page 13: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Workflows Requirements Analysis Design Implementation Test

Page 14: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Requirements

Gather requirements from users Put them into a form everyone can

understand – Use Cases!!! Validate requirements with users Iterate until you have agreement

Page 15: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Analysis

“High Level Design”– Domain class diagrams– Sequence diagrams– State diagrams

Review with customer, development Iterate until you get agreement

Page 16: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Design

“Low Level Design”– Refine existing class definitions– Implementation level classes– Interfaces developed

Function prototypes Review with customer, development Iterate until you get agreement Blueprint for development

Page 17: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Implementation

Code Debug Unit test Go back to design if required

Page 18: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Test

Does the system implement the function specified in the use cases?

Is the code defect free?

Page 19: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Phases vs. Workflows

PhasesCore

WorkflowsInception Elaboration Construction Transition

Requirements

Analysis

Design

Implementation

Test

Page 20: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Object Oriented Design Tools

Page 21: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Use Case Diagrams

A use case diagram is a way to graphically represent the set of use cases that have been created for a system.

Page 22: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

A use case starts out with an actor.An actor is a role that a user playswith respect to the system. For example,a customer, a clerk, a supervisor, etc.

In a use case diagram, an actor is shownas a stick figure.

Buy Book

Actors carry out use cases. A usecase is some activity that the actordoes using the system.

In a use case diagram, a use case isshown as an oval with the name of theactivity written inside of the oval.

The arrow indicates that thisactor carries out this use case.

Page 23: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

A use case diagram shows a group of actors and related use cases

customer

sales person

Store Manager

buy book

order book

check inventory

add books

Page 24: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Storyboard

Objective: Fill in details of a use case Develop a scenario that describes one set of

interactions between an actor and the system.

Use a storyboard to lay out the sequence of operations.

Example …

Page 25: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Example: Create controller software for an ATM machine

withdraw cash

Consider the use case:

Page 26: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

a Storyboard

display “Swipe Card”

ask Bank toValidate account

validate amount

userswipes card

display “Enter PIN”

userEnters PINon keypad

Bank returnsBalance

display“Amount to withdraw”

userenters amount

on keypad

dispensecash

tell Banknew Balance

print receipt

Page 27: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Identify the Objects

Goal: identify the classes and objects that form the vocabulary of the problem domain

Difficult to get it right – takes practice Look for:

– tangible things– roles– places– events– devices

Page 28: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Potential Objects

display “Swipe Card”

ask Bank toValidate account

validate amount

userswipes card

display “Enter PIN”

userEnters PINon keypad

Bank returnsBalance

display“Amount to withdraw”

userenters amount

on keypad

dispensecash

tell Banknew Balance

print receipt

Page 29: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Filter

What objects are outside the scope of the problem?

Do some objects refer to the same thing?

Page 30: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

CRC Card

Create a CRC card for each class

Class Name

ResponsibilitiesCollaborators

Page 31: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

CRC Card

Class Name

ResponsibilitiesCollaborators

Account Name

Account Number

Account Balance

getName ( )

The class’s responsibilities refer to the data that the class is responsible for, and the operations that are provided to manage that data.

Every piece of data must be owned and managed by some class!

Look for strong cohesion in a class. Strong Cohesion means that all class data and functions support the purpose of the class.

Page 32: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

CRC Card

Class Name

ResponsibilitiesCollaborators

A class’s collaborators are other classes that this class needs to do it’s job. To find collaborators, look for messages sent by this class.

Look for low coupling in domain classes. Low coupling means a class is relatively independent of other classes. Our domain classes will have few or no collaborators.

Page 33: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Relationships

Lay CRC cards out on a table. Do CRC cards satisfy use cases? Look for message patterns.

– How are objects of this class created?– Who sends messages to objects of this

class? Can this class be generalized? Are there composition relationships?

Page 34: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Next steps

Create commented header files for each class using CRC cards– Describe data elements of the class– For each operation in the class

What is it’s purposeWhat parameters does the operation

require?What values, if any, does the function

return?Document pre- and post-conditions

Page 35: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

UML – From Design to Implementation

Page 36: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Reference Material for this slide presentation“UML Distilled”

Page 37: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

What is UML?

UML stands for Unified Modeling Language.

It is a methodology and a “language” used toexpress object oriented analysis and design.

Its strength is in it ability to communicate programdesign in a concise, standard notation.

Page 38: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

UML is a standard notation, combining the workof several pioneers in the field of object orienteddesign methodology:

Grady BoochJames RumbaughIvar Jacobsen

Page 39: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

UML ToolsUse Case Diagrams

Class Diagrams

Sequence Diagrams

State Diagrams

Activity Diagrams

and more …

Page 40: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Class Diagram

Class Diagrams show the attributes and operationsthat belong to a class, and the relationships betweenclasses.

Page 41: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Book

- title: string- author: string- publisher: string…

The class name appears atthe top of the class diagram.

Next we list the attributes or datamembers of the class, in the form

visibility name : type = defaultValue

visibility is + (public) - (private) # (protected)

+ Book ( )+ ~Book( )+ getTitle ( ): string+ setTitle (:string): void…

Finally we list the operations or memberfunctions of the class, in the form

visibility name (parameterList): return type

Page 42: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Book

- title: string- author: string- publisher: string…

+ Book ( )+ ~Book( )+ getTitle ( ): string+ setTitle (:string): void…

Book

titleauthorpublisher…getTitle( )setTitle( )…

Class diagrams can be derivedfrom CRC cards

Page 43: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Customer Book

buy*

Associations

In this class diagram we note that 1customer may buy zero or more books.

labels the association

multiplicity 1 one and only one 0..1 zero or one * zero to any positive number

1

Page 44: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Employee

Manager

Inheritance

Inheritance is shown withan arrow that points from thederived class to the base class.

A Manager is an Employee.

Page 45: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Automobile

Engine

Composition

Composition is shown withan diamond going from thecontaining class to thecomponent.

An Automobile has an Engine

Page 46: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Sequence Diagrams

Class diagrams are static. They do not describe the over-all flow of control in a program. Sequence diagrams are useful in visualizing the sequence in which things happen in a program and how messages flow from object to object.

Page 47: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

display keypad reader account bank dispenser control

display “Swipe Card”

getAccount Number

validate

getCurrentBalance

display “Enter PIN”

getPIN

display “Enter amount to withdraw”

getAmount

giveCash

1

2

3

4

5

6

7

8

9

Sequence diagram for an ATM Machine

user

swipes card

enterspin

entersamount

these are objects

. . .

a message sent to an objectis a call to a function in thatobject

Page 48: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

display “Swipe Card”

ask Bank toValidate account

userswipes card

display “Enter PIN”

userEnters PINon keypad

Bank returnsBalance

display keypad reader

display “Swipe Card”

display “Enter PIN”

account

A sequence diagram can be derived from a storyboard.

Page 49: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

State Diagrams

State diagrams have been used for a long time to describe the behavior or a system. UML state diagrams are useful in describing all of the possible states that an object can get into, and what actions move it from one state to another.

Page 50: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Disabled

Waitingfor Card

ReadingCard

Sending Data

start

card sensed

card removed

data received

State Diagram for Card Reader in the ATM Example

Page 51: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Activity Diagrams

Activity diagrams are similar to state diagrams, but they are useful in visualizing the workflow in a program when the program has many decision points.

Page 52: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

ReceiveRead Card

Order

ReadCard

Display“Swipe Card

Again”

Send Datato Bank

Activity Diagram for Card Reader in the ATM Example

goodread

badread

start

end

Page 53: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

From UML to Code

Let’s do the design for a PiggyBank class,and then see how we move from the designto code.

Page 54: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

What are the attributes of a Piggy Bank?

An object’s attributes will definethe member data of the class.

color = pink

height = 6”

width = 10”

amount of moneyin the bank

depending upon the application, some attributesare more important than others

Page 55: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

An object also has behaviorsbehaviors will define the member functions of the class

Put money in!

Take money out!

Count the money in the bank

Page 56: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

CRC CardPiggyBank

Remember …responsibilities includethe data that the classis responsible for and any functions necessaryto operate on that data.

moneyInBank

putMoneyIn( )takeMoneyOut( )countMoney( )

we’ll ignorecollaboratorsfor now …

the key data memberis the amount of moneyin the bank.

Page 57: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

PiggyBank

moneyInBank

putMoneyIn( )takeMoneyOut( )countMoney( )

- : double

+ : void+ :double+ :double

+ PiggyBank( )

CRC Card

Class Diagram

Page 58: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

-

PiggyBank( )

Class Diagram

PiggyBank

class { private:

moneyInBank:double

;

public:+

;

putMoneyIn(double)takeMoneyOut(double)countMoney( )

+++

:::

voidvoiddouble

; ;;

};

Page 59: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

The code required to implement the functions isfairly trivial in this case.

putMoneyIn( ) should just add the value of theparameter to the money in the bank. It doesnot return anything.

void putMoneyIn( double money){ moneyInBank+=money;}

Page 60: CS 1410 Object Oriented Design. Objectives At the end of this lesson, students should be able to: Describe the software life cycle. Given a computing.

Write the Function Prologue

Class PiggyBank{ private: double moneyInBank; public: PiggyBank( );

// purpose: add to moneyInBank // parameters: the amount to add // a positive number // returns: none // pre-conditions: param is positive // post-conditions: moneyInBank = moneyInBank + the parameter void putMoneyInBank( double );

double countMoney ( ); double takeMoneyOut( double );};


Recommended