topic 9summer 2003 1 ics 52: introduction to software engineering lecture notes for summer quarter,...

44
Topic 9 Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture notes written by Sommerville, Frost, & Easterbrook. Duplication of course material for any commercial purpose without the written permission of the lecturers is prohibited

Post on 20-Dec-2015

220 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 1

ICS 52: Introduction to Software Engineering

Lecture Notes for Summer Quarter, 2003

Michele RousseauTopic 9

Partially based on lecture notes written by Sommerville, Frost, & Easterbrook. Duplication of course material for any commercial purpose without the written

permission of the lecturers is prohibited

Page 2: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 2

Today’s Lecture

A brief introduction to Classes & Objects

Page 3: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 3

Noun extraction for design• Complements design by information

hiding

Page 4: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 4

Remember this?

issue ()sendReminder ()acceptPayment ()sendReceipt ()

invoice#dateamountcustomer

Invoice

invoice#dateamountcustomer#

Receipt

invoice#dateamountcustomer#

Payment

customer#nameaddresscredit period

Customer

• Invoice Processing System – Object Model

This system can: •Issue invoices to customers

•Receive payments•Issue receipts for payments •Issue reminders for unpaid invoicesThe dashed line means that one object

uses the attributes or services of another object

Page 5: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 5

Choosing classes & objects

At the conceptual level: an object is a set of responsibilities, including responsibility for itself (encapsulates functions and data)

At the specification level: an object is a set of methods (its interface) , which can be invoked by itself or other objects

At the implementation level: an object is code (methods) and data (attributes)

Object Oriented approach attempts to manage complexity in real-world problems

Page 6: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 6

Objects

Have Public and Private sides OOD –views the world as a system of

cooperating collaboration agents.

Page 7: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 7

Some Terminology

Encapsulation – bundling operations and data that are conceptually linked (like putting them in a capsule)

Information Hiding – Making the capsule opaque

Method – an action Attribute – a variable/constant Object – primitive programming element Class – a generic specification for an

arbitrary number of similar objects – (abstract, template)

Page 8: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 8

An OOD Process

Find the classes in your system Determine operations for each class Determine how objects will need to

collaborate with each other

Page 9: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 9

Hints for Choosing Classes

How do I find classes, attributes and so on?• Look at the requirements

»classes often correspond to nouns»attributes often correspond to abstract

nouns»operations often correspond to verbs

Page 10: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 10

Determining Classes

Model physical objects (employees, invoices, printers, etc..)

If more than 1 word is used for the same concept choose the one that is most meaningful.

Be wary of adjectives – does it describe new behavior?

Model known interfaces Model the values of attributes – but

don’t model attributes• e.g. Line and length – class or attribute

Page 11: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 11

A class should ...

represent a coherent concept• Principle: Low Coupling, High Cohesion

have a small, well-defined set of responsibilities

be named with a singular noun that says what each each instance of the class is

have no more than 10-20 operations

Page 12: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 12

An Example

FastData Inc. wants a subsystem to process office supply orders via the Web. The user will supply via a form their name, password, account number, and a list of supplies along with an indication of the quantities desired. The subsystem will validate the input, enter the order into a database, and generate a receipt with the order number, expected ship date, and the total cost of the order. If the validation step fails, the subsystem will generate an error message describing the cause of the failure

Page 13: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 13

You may need to rewrite

Make it concise. “FastData, Inc. employees may order

office supplies via the Internal Web and receive a receipt confirming the order. The order must include the user name, user password, account number, and the list of supplies. A receipt must be generated containing an order number, ship date, and total cost. If the order is valid, it must be entered into an order database. If the order is invalid, an error message must be generated.”

Page 14: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 14

Formalize the Strategy

Identify the nouns of the description, which serve as the basis for identifying the subsystem’s classes.

Look for out-of-domain nouns (and throw them out!)

Look for abstract nouns (use these for attributes)

The remaining nouns are good candidates for classes!

Page 15: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 15

Find the nouns

“FastData, Inc. employees may order office supplies via the Internal Web and receive a receipt confirming the order. The order must include the user name, user password, account number, and the list of supplies. A receipt must be generated containing an order number, ship date, and total cost. If the order is valid, it must be entered into an order database. If the order is invalid, an error message must be generated.”

Page 16: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 16

Nouns

– Employees– Office Supplies Item– Internal Web– Receipt – Order – User name– User password

– Account number

– Order number– Ship date– Total cost– Order database– Error message– List of supplies

Page 17: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 17

Nouns

Out-of-Domain• Internal Web

Abstract• user name• user password• account number• order number• ship date• total cost• list of supplies

Good Candidates• employee• item (was office

supplies)• receipt• order• order database• error message

Notes• We have decided not

to worry about the Web in this design. Instead we focus on the inputs and outputs and defer the Web details until later.

Page 18: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 18

Basic Classes

Employee

NamePasswordAccount #

Order NumberEmployeeItem

Error Message

Item

OrderShip DateTotal cost

Receipt

Order

Order Database

This gives us a starting place to refine and revise

Page 19: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 19

Assigning Responsibilities

Responsibilities include 2 key items• The knowledge an object maintains• The actions an object can perform

An object is a client when it requests services from another object.

An object is a server when it fulfills a request from another object.

Where to look –• Requirements• Classes

Page 20: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 20

Identifying Responsibilities

Look for the verbs • Which ones clearly represent actions

that some object must perform• Note where information is mentioned

» Information an object must maintain and manipulate

Look at they system as a whole (walkthrough)

Look at the classes

Page 21: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 21

Assigning Responsibilities

Try to evenly distribute system intelligence

State responsibilities as generally as possible

Keep behavior with related information Keep information about 1 thing in 1

place Share responsibilities among related

objects

Page 22: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 22

What Operations go with which Class?

Employee

NamePasswordAccount #

Order NumberEmployeeItemSendReceipt()SendErrorMsg()AddItem()

Error Message

Item

OrderShip DateTotal cost

Receipt

Order

Order Database

Page 23: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 23

Final Notes

Refine, Revise Define relationships

Page 24: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 24

Design Recap

Page 25: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 25

Important concepts

Architectural styles Information hiding Noun extraction Uses diagram Comprises diagram

Page 26: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 26

How do we decide if a design is the best possible design?

Ability to predict comes with experience Qualities to look for: Verifiability,

Maintainability, Repairability, Evolvability, Reusability, Portability, Understandability, Interoperability

Principles to maintain: Rigor & formality, Separation of concerns, Modularity, Abstraction, Anticipation of change, Generality

Page 27: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 27

What is a Good Class?

…and what should not be a class? A class should be named with a noun

• Example: “class Book” A class should not represent a task or operation

• Don’t do this: “class FindABook”• Don’t have classes described as “performing” something

A class should contain several related operations• These correspond to the class’ responsibilities

A class should contain at least one attribute A class should represent a single abstraction

Page 28: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 28

Is fan-in, fan-out relevant?

Yes, but it’s not as important as other indications of a good design

High cohesion and low coupling are the most important

For smaller systems, the uses diagram is the next most important

For larger systems, the comprises diagram is also important

Page 29: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 29

How does high level architecture affect module interaction?

Architectural styles restrict the way in which components can be connected• Prescribe patterns of interaction• Promote fundamental principles

»Rigor, Separation of concerns, Modularity, Abstraction, Anticipation of change, Generality, Incrementality

»Low coupling, High cohesion

Page 30: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 30

Do we have to code up the modules?

Yes, but later.

Page 31: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 31

Why do we define levels in the uses diagram?

The process of doing so helps identify cycles (which are usually bad)

The levels are used in making an integration test plan

Page 32: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 32

How many levels should we have in a uses diagram?

It depends. Small systems may only have 2 or 3 Larger systems may have many more,

or they may remain fairly “shallow”

Page 33: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 33

Acceptance testing?

Acceptance testing is performed after implementation and integration testing is complete, before the product is given to the client

Acceptance test plans are made during the requirements phase

The acceptance test plan includes a high-level description of what is being tested, and specific test inputs, along with expected outputs.

Page 34: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 34

Integration testing?

Integration testing is performed after implementation and module testing, before acceptance testing

The integration test plan is made during design

The integration test plan includes a plan of the order of integration and specific test cases.

Page 35: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 35

Integration Testing

Page 36: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 36

V-Model of Development and Testing

Develop Acceptance TestsAcceptance Test Review

Requirements ReviewDevelop Requirements Execute System Tests

Develop Integration TestsIntegration Tests Review

Design ReviewDesign Execute Integration Tests

Develop Unit TestsUnit Tests Review

Code ReviewCode Execute Unit Tests

Page 37: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 37

Integration Test Plans

Goal (Why?)• Ensure modules make compatible assumptions about

each other. • Exercise interfaces between modules, as opposed to

functionality within modules Hard part:

• Identifying interactions that reveal agreement or disagreement on assumptions

Approach (How?)• Combine more and more modules• Use USES hierarchy

» Work up from lowest numbers Use test harnesses to test each group of modules

» Work down from highest numbers Use stubs as mockups to test each group of modules

Test execution can be done during implementation effort

Page 38: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 38

Integration Test Example

Provided Interface

Main componentRequired Interface

Provided Interface

SubcomponentRequired Interface

Provided Interface

SubcomponentRequired Interface

Provided Interface

SubcomponentRequired Interface

Provided Interface

SubcomponentRequired Interface

Provided Interface

SubcomponentRequired Interface

Provided Interface

SubcomponentRequired Interface

Provided Interface

SubcomponentRequired Interface

Provided Interface

SubcomponentRequired Interface

Page 39: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 39

Integration Testing Tools

Extra code you write for integration testing. Needed because not all modules are ready at the same time.

Harnesses or drivers•Call or invoke modules and pass parameters

to them

Stubs•Are called by modules, do minimal

processing, return reasonable values

Page 40: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 40

Test Harnesses (bottom-up integration)

Provided Interface

SubcomponentRequired Interface

Provided Interface

SubcomponentRequired Interface

Provided Interface

SubcomponentRequired Interface

Provided Interface

SubcomponentRequired Interface

Provided Interface

SubcomponentRequired Interface

Provided Interface

SubcomponentRequired Interface

Provided Interface

SubcomponentRequired Interface

Provided Interface

Test HarnessRequired Interface

Provided Interface

Test HarnessRequired Interface

Page 41: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 41

Stubs(top-down integration)

Provided Interface

Main componentRequired Interface

Provided Interface

StubRequired Interface

Provided Interface

StubRequired Interface

Provided Interface

StubRequired Interface

Page 42: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 42

Stubs

Provided Interface

Main componentRequired Interface

Provided Interface

StubRequired Interface

Provided Interface

StubRequired Interface

Provided Interface

SubcomponentRequired Interface

Provided Interface

StubRequired Interface

Provided Interface

StubRequired Interface

Page 43: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 43

Stubs

Provided Interface

Main componentRequired Interface

Provided Interface

SubcomponentRequired Interface

Provided Interface

StubRequired Interface

Provided Interface

SubcomponentRequired Interface

Provided Interface

StubRequired Interface

Provided Interface

StubRequired Interface

Page 44: Topic 9Summer 2003 1 ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 9 Partially based on lecture

Topic 9 Summer 2003 44

Integration Testing Strategies

Integrate and test increasingly larger subsets of modules

Top-down integration testing•Can be done before units are fully coded•Requires stubs

Bottom-up integration testing•Requires test harnesses or drivers•Can thoroughly test lower modules but

postpones detection of major integration problems

Hybrid of both most common in practice