software engineering si334 lessons 24, 26 – 28 & 30: classical & object-oriented design...

46
Software Engineering SI334 Lessons 24, 26 – 28 & 30: Classical & Object-Oriented Design October 6, 8, 10, 15, 2014

Upload: charlotte-holt

Post on 01-Jan-2016

213 views

Category:

Documents


0 download

TRANSCRIPT

So

ftw

are

En

gin

eeri

ng

SI3

34

Lessons 24, 26 – 28 & 30:Classical & Object-Oriented Design

October 6, 8, 10, 15, 2014

So

ftw

are

En

gin

eeri

ng

SI3

34

2

Data and ActionsData and Actions

Two aspects of a productTwo aspects of a product Actions that operate on data Data on which actions operate

The two basic ways of designing a productThe two basic ways of designing a product Operation-oriented design Data-oriented design

Third wayThird way Hybrid methods For example, object-oriented design

© The McGraw-Hill Companies, 2011

So

ftw

are

En

gin

eeri

ng

SI3

34

4

* Object-Oriented Design* Object-Oriented Design

Classes are extracted during the object-oriented analysis Classes are extracted during the object-oriented analysis workflow, andworkflow, and Designed during the design workflow

AccordinglyAccordingly Classical architectural design corresponds to part of the

object-oriented ____________workflow

Classical detailed design corresponds to part of the object-oriented ____________workflow

© The McGraw-Hill Companies, 2011

analysisanalysis

designdesign

So

ftw

are

En

gin

eeri

ng

SI3

34

5

**Object-Oriented DesignObject-Oriented Design Goal:Goal: Design product Design product

in terms of objects identified during OOAin terms of objects identified during OOA

OOD consists of two key steps:OOD consists of two key steps:1. Complete the detailed class diagram2. Perform the detailed design

So

ftw

are

En

gin

eeri

ng

SI3

34

6

**Object-Oriented DesignObject-Oriented Design Completing the detailed class diagram consists of: Completing the detailed class diagram consists of:

1. Determining the formats of the attributesa. Formats of attributes generally deduced directly from analysis

artifacts

2. Determining the methods and assigning them to the relevant classesa. Methods determined by constructing interaction diagrams for each

scenario. Two flavors:i. Collaboration diagrams (Spatial) and ii. Sequence Diagrams (Temporal)

b. Methods assigned to classes by designing the product in terms of clients of objects

So

ftw

are

En

gin

eeri

ng

SI3

34

7

*Determining Class’ Attributes*Determining Class’ Attributes

Consider class Elevator Controller If User wants to check and update

requests, needs requests attribute Needs methods:

check requests, update requests

Detailed: As used here means that all method names, and (as a by-product) attributes ID’d by designer, are represented on the diagram

So

ftw

are

En

gin

eeri

ng

SI3

34

9

Interaction DiagramsInteraction Diagrams

Construct interaction diagrams for Construct interaction diagrams for eacheach scenario; focus is scenario; focus is on objects and the on objects and the messages passedmessages passed between them. between them. “Passing a message” between objects really means having

one object invoke a public method of another object.

Example:Example: An elevator An elevator controller that asks the doors controller that asks the doors to open and close themselvesto open and close themselves

An interaction is implemented by a group of objects that collaborate by exchanging messages.

These messages are represented along the links that connect the objects, using arrows pointed towards the recipient of the message.

Elevator Controller Elevator Doors

close doors

open doors

So

ftw

are

En

gin

eeri

ng

SI3

34

10

*Collaboration Diagrams:*Collaboration Diagrams: spatialspatial representation representation

Focus is on the Focus is on the relationshipsrelationships between objects between objects Structure becomes clear Timing info is obscure, messages numbered to indicate

sending orderActors represent the triggering of interactions Actors represent the triggering of interactions by an element that is external to the systemby an element that is external to the system

Example: A Person Calling an Elevator

Example: Elevator Controller requesting Elevator move up one floor

Elevator Controller

Elevator

*move up one floor

So

ftw

are

En

gin

eeri

ng

SI3

34

11

*Sequence Diagrams:*Sequence Diagrams: temporaltemporal representation representation

Focus is on message broadcast chronology of interactions Focus is on message broadcast chronology of interactions between objects. between objects.

Loops and conditional branches may be represented.Example: Shows that object A sends a message to object B or object C according to a condition (X).

An object is represented by a rectangle and a vertical bar called the object's lifeline. The message sending order is indicated by position of message on vertical axis. Vertical axis may be labeled to express temporal constraints precisely.

The following diagram shows a loop fragment.

So

ftw

are

En

gin

eeri

ng

SI3

34

13

Use Scenarios to Create Interaction DiagramsUse Scenarios to Create Interaction Diagrams

Example of a Normal Use Scenario

So

ftw

are

En

gin

eeri

ng

SI3

34

14

Collaboration DiagramCollaboration Diagram

Start with diagram of objects and actors

So

ftw

are

En

gin

eeri

ng

SI3

34

15

*Collaboration Diagram*Collaboration Diagram

Use scenario to identify messages passed among objects

Most other messages, such as press floor button (step 1) open doors (steps 6, 14) go from an actor to an object, or from one object to another

Some messages, such as start timer (steps 7, 15) go from an object to itself

So

ftw

are

En

gin

eeri

ng

SI3

34

16

*ICE- Complete Elevator Collaboration *ICE- Complete Elevator Collaboration DiagramDiagram

So

ftw

are

En

gin

eeri

ng

SI3

34

17

*Equivalent Sequence Diagram*Equivalent Sequence Diagram

So

ftw

are

En

gin

eeri

ng

SI3

34

19

Homework- Interaction DiagramsHomework- Interaction Diagrams

Produce an interaction diagram (your choice of sequence or collaboration) for the Apartment Automatic Garage DoorApartment Automatic Garage Door Scenario 1: “User swipes card and drives car into garage.”

Scenario 1

1. Driver A swipes card.2. If door is open, GarageDoorController resets timer.3. If door is closed, GarageDoorController sends msg to

Garage Door to open.4. When door is fully opened, DoorOpenSensor notifies

GarageDoorController.5. GarageDoorController resets timer.6. Timer times out; GarageDoorController notified.7. GarageDoorController sends msg to GarageDoor to close.8. When door is fully closed, DoorClosedSensor notifies

Garage DoorController.

So

ftw

are

En

gin

eeri

ng

SI3

34

20

*Assigning Methods to Classes*Assigning Methods to Classes

A well-structured Interaction Diagram gives very specific A well-structured Interaction Diagram gives very specific information on what responsibilities a class should have.information on what responsibilities a class should have.

Main question, do we assign an action to a class or to a Main question, do we assign an action to a class or to a client of that class? client of that class?

Examples• close doors assigned to?• move one floor down assigned to?

Typical:Typical: Class at head of arrow on Interaction Diagram gets tasked with the Class at head of arrow on Interaction Diagram gets tasked with the labeled responsibility, and implements it as a method. labeled responsibility, and implements it as a method.

Things to consider:• Information hiding

• Reducing # of copies of an action

• Responsibility-driven design

Elevator Doors

Elevator

So

ftw

are

En

gin

eeri

ng

SI3

34

21

**Determine Clients of ObjectsDetermine Clients of Objects

Design Product in Terms of Clients of Objects to determine Design Product in Terms of Clients of Objects to determine which objects should create other objectswhich objects should create other objects Draw a single arrow from each object to a client of that object Objects that are not clients of any object have to be initiated,

probably upon system launch, Additional methods may be needed.

elevator controller needs method elevator event loop so that elevator application can call it.

This Completes High-Level Design for OOD!

So

ftw

are

En

gin

eeri

ng

SI3

34

22

ICE- Detailed Class DiagramsICE- Detailed Class Diagrams

ICE: Complete the Detailed Class Diagram for the Elevator, Elevator, showing all method names and attributes identified by the designer for each class.

So

ftw

are

En

gin

eeri

ng

SI3

34

23

Homework- Detailed Class DiagramsHomework- Detailed Class Diagrams

Homework: Produce a Detailed Class Diagram for the Apartment Automatic Garage Door, Apartment Automatic Garage Door, showing all method names and attributes identified by the designer.

Scenario 1

1. Driver A swipes card.

2. If door is open, GarageDoorController resets timer.

3. If door is closed, GarageDoorController sends msg to Garage Door to open.

4. When door is fully opened, DoorOpenSensor notifies GarageDoorController.

5. GarageDoorController resets timer.

6. DoorCloseTimer times out; GarageDoorController notified.

7. GarageDoorController sends msg to GarageDoor to close.

8. When door is fully closed, DoorClosedSensor notifies GarageDoorController

So

ftw

are

En

gin

eeri

ng

SI3

34

24

*Step 2 of OOD:*Step 2 of OOD: Perform Detailed Design Perform Detailed Design

Detailed design of method Detailed design of method elevator event loopelevator event loop, draws , draws heavily from prior UML diagrams. Design Team:heavily from prior UML diagrams. Design Team: Should not do too much:

• Detailed design should not become complete code

Should not do too little:• It is essential for detailed design to fully indicate how all

functionality is met.

So, what should detailed design’s output be? So, what should detailed design’s output be?

Detailed Design’s output is program description language for all the Classes in Detailed Class diagram, with fully described interfaces.

So

ftw

are

En

gin

eeri

ng

SI3

34

25

*Step 2 of OOD:*Step 2 of OOD: Perform Detailed Design Perform Detailed Design

Elevator Controller Loop

[no requests pending, doors closed]

[elevator stopped,

request(s) pending]

[elevator stopped,

no requests pending]

[button pushed, button unlit]

[elevator moving in

direction d, floor f is next]

[user has requested stop

at floor f]

[no request to stop at

floor f]

Continue Moving

do/ move elevator one floor in direction d

Process Request

Determine If Stop Requested

do/ check requests

Go Into Wait Statedo/ close elevator doors

after timeout

Process Next Request

do/ move elevator one floor in direction of next request.

[floor button

lit]

[floor button unlit]

[button pushed, button lit]

Stop At Floor

do/ stop elevator do/ open doors do/ update requests

[elevator button

lit]

[elevator button unlit]

do/ update requests do/ turn on button

Close Elevator Doors

do/ close doors after timeout

Floor Button Offdo/ turn off floor

button

Elevator Button Off

do/ turn off elevator button

So

ftw

are

En

gin

eeri

ng

SI3

34

26

ICE/Homework- Detailed DesignICE/Homework- Detailed Design

ICE/Homework: Produce a Detailed Design for method garageDoorControlLoop in class GarageDoorController for the Apartment Automatic Garage Door, Apartment Automatic Garage Door, using Java-like pseudo-code.

So

ftw

are

En

gin

eeri

ng

SI3

34

27

Real-Time Design TechniquesReal-Time Design Techniques Difficulties associated with real-time systemsDifficulties associated with real-time systems

Inputs come from the real world• Software has no control over the timing of the inputs

Frequently implemented on distributed software• Communications implications

• Timing issues

Problems of synchronization• Race conditions

• Deadlock (deadly embrace)

Major difficulty in design Major difficulty in design of real-time systems?of real-time systems?

• Determining whether timing constraints are met by the design

© The McGraw-Hill Companies, 2011

So

ftw

are

En

gin

eeri

ng

SI3

34

28

* Design Testing* Design Testing

Design reviews are essentialDesign reviews are essential A client representative is not usually present (except in

DoD procurements)

Types of faults uncovered:Types of faults uncovered:

© The McGraw-Hill Companies, 2011

logic faults interface faults lack of exception handling non-conformance to specification

So

ftw

are

En

gin

eeri

ng

SI3

34

29

*Testing During the Design Workflow*Testing During the Design Workflow

Goal of Design Testing- answer the following:Goal of Design Testing- answer the following: Is the specification accurately and completely incorporated into the design? Is the design itself correct?

• No logic faults• Interface for each class fully defined.

Design reviews. Purpose is to show that Design correctly reflects the Design reviews. Purpose is to show that Design correctly reflects the Specification. How can this be shown?Specification. How can this be shown?

Show how each normal/abnormal scenario is met by the design. Critical that proper set of scenarios was developed during OOA.

So

ftw

are

En

gin

eeri

ng

SI3

34

30

Formal Techniques for Detailed DesignFormal Techniques for Detailed Design

Implementing a complete product and then proving it Implementing a complete product and then proving it correct is hardcorrect is hard

However, use of formal techniques during detailed design However, use of formal techniques during detailed design can helpcan help Correctness proving can be applied to module-sized pieces The design should have fewer faults if it is developed in

parallel with a correctness proof If the same programmer does the detailed design and

implementation• The programmer will have a positive attitude to the

detailed design• This should lead to fewer faults

© The McGraw-Hill Companies, 2011

So

ftw

are

En

gin

eeri

ng

SI3

34

31

*Case Tools for OOD*Case Tools for OOD

UpperCASE toolsUpperCASE tools Examples of UpperCASE tools:

• Software through Pictures, • Visual Paradigm• Rational Rose

Built around data dictionary Screen, report generators What automated support could be provided by a case tool that

represents OOD using UML?

• Automated conversion between Diagrams,

• Generation of Class Constructs from Class Design with Class names, attributes, methods filled in.

• Programmers focus on fleshing out method bodies

So

ftw

are

En

gin

eeri

ng

SI3

34

32

*Metrics for OOD*Metrics for OOD

What Metrics can be used to describe various aspects of What Metrics can be used to describe various aspects of the Design? the Design?

One is McCabe’s Cyclomatic complexity. Measure based One is McCabe’s Cyclomatic complexity. Measure based on # of control flow decisions, can apply to pseudo-code.on # of control flow decisions, can apply to pseudo-code. the number of binary decisions plus 1, a metric of design quality, the lower the M the better

What other aspects of a Design can be Measured?What other aspects of a Design can be Measured? Raw number of modules gives a crude measure of size of the targeted product. Couplings between Modules and Cohesiveness of Modules.

• Advantage: Easy to compute, can be automated

• Disadvantage: Measures control complexity only, does not measure data

complexity.

So

ftw

are

En

gin

eeri

ng

SI3

34

33

Design and AbstractionDesign and Abstraction

Classical design activities Classical design activities Architectural design Detailed design Design testing

Architectural designArchitectural design

Detailed designDetailed design

© The McGraw-Hill Companies, 2011

Each module is designed

• Specific algorithms, data structures

Input: Specifications Output: Modular decomposition

So

ftw

are

En

gin

eeri

ng

SI3

34

34

Data and ActionsData and Actions

Two aspects of a productTwo aspects of a product Actions that operate on data Data on which actions operate

The two basic ways of designing a productThe two basic ways of designing a product Operation-oriented design Data-oriented design

Third wayThird way Hybrid methods For example, object-oriented design

© The McGraw-Hill Companies, 2011

So

ftw

are

En

gin

eeri

ng

SI3

34

35

Operation-Oriented DesignOperation-Oriented Design

Data flow analysisData flow analysis Use it with most specification methods (Structured

Systems Analysis here)

Key point: We have detailed action information from the Key point: We have detailed action information from the DFD DFD

Figure 14.1

© The McGraw-Hill Companies, 2011

So

ftw

are

En

gin

eeri

ng

SI3

34

36

Data Flow AnalysisData Flow Analysis

Every product transforms input into outputEvery product transforms input into output

Figure 14.1

So

ftw

are

En

gin

eeri

ng

SI3

34

37

Data Flow AnalysisData Flow Analysis

Every product transforms input into outputEvery product transforms input into output DetermineDetermine

“Point of highest abstraction of input” “Point of highest abstract of output”

After Figure 14.2

So

ftw

are

En

gin

eeri

ng

SI3

34

38

Data Flow Analysis (cont.)Data Flow Analysis (cont.)

Use these points to decompose the product into three Use these points to decompose the product into three modulesmodules

Repeat stepwise until each module has high cohesion Repeat stepwise until each module has high cohesion (degree of interaction within a module)(degree of interaction within a module) Minor modifications may be needed to lower the coupling

(degree of interaction between two modules)

© The McGraw-Hill Companies, 2011

Figure 14.2

So

ftw

are

En

gin

eeri

ng

SI3

34

39

*Mini Case Study: Word Counting*Mini Case Study: Word Counting

Example:Example:

Design a product which takes as input a file name, and returns the number of words in that file (like UNIX wc )

Figure 14.3

© The McGraw-Hill Companies, 2011

So

ftw

are

En

gin

eeri

ng

SI3

34

40

*Mini Case Study: Word Counting (cont.)*Mini Case Study: Word Counting (cont.)

First refinementFirst refinement

Now refine the two modules of communicational cohesionNow refine the two modules of communicational cohesion**(*module performs series of operations (on same data) related by sequence of steps to be followed)(*module performs series of operations (on same data) related by sequence of steps to be followed)

Figure 14.4

© The McGraw-Hill Companies, 2011

So

ftw

are

En

gin

eeri

ng

SI3

34

41

Second refinementSecond refinement

All eight modules now have functional cohesionAll eight modules now have functional cohesion**(*module that performs exactly one operation or achieves a single goal)(*module that performs exactly one operation or achieves a single goal)

Mini Case Study: Word Counting (cont.)Mini Case Study: Word Counting (cont.)

Figure 14.5

© The McGraw-Hill Companies, 2011

So

ftw

are

En

gin

eeri

ng

SI3

34

42

Data Flow Analysis ExtensionsData Flow Analysis Extensions

In real-world products, there is In real-world products, there is More than one input stream, and More than one output stream

© The McGraw-Hill Companies, 2011

So

ftw

are

En

gin

eeri

ng

SI3

34

43

Data Flow Analysis Extensions (cont.)Data Flow Analysis Extensions (cont.)

Find the point of highest abstraction for each streamFind the point of highest abstraction for each stream

Continue until each module has high cohesionContinue until each module has high cohesion Adjust the coupling if needed

Figure 14.8

© The McGraw-Hill Companies, 2011

So

ftw

are

En

gin

eeri

ng

SI3

34

44

ICE- Course Project Data Flow AnalysisICE- Course Project Data Flow Analysis

ICE: Produce a high-level Data Flow Diagram (DFD) for your course project, showing the point of highest abstraction of input and point of highest abstraction of output.

So

ftw

are

En

gin

eeri

ng

SI3

34

45

*Detailed Design*Detailed Design

The architectural design is completeThe architectural design is complete So proceed to the detailed design

Two formats for representing the detailed design:Two formats for representing the detailed design:

© The McGraw-Hill Companies, 2011

Tabular Pseudocode (PDL—program description language)

So

ftw

are

En

gin

eeri

ng

SI3

34

46

Detailed Design: Tabular FormatDetailed Design: Tabular Format

Figure 14.6(a)

© The McGraw-Hill Companies, 2011

So

ftw

are

En

gin

eeri

ng

SI3

34

47

Detailed Design: PDL FormatDetailed Design: PDL Format

Figure 14.7© The McGraw-Hill Companies, 2011

So

ftw

are

En

gin

eeri

ng

SI3

34

48

Data-Oriented DesignData-Oriented Design

Basic principleBasic principle The structure of a product must conform to the structure

of its data

Three very similar methodsThree very similar methods Michael Jackson [1975], Warnier [1976], Orr [1981]

So

ftw

are

En

gin

eeri

ng

SI3

34

50

Data-Oriented DesignData-Oriented Design

Basic principleBasic principle The structure of a product must conform to the structure

of its data

Three very similar methodsThree very similar methods Michael Jackson [1975], Warnier [1976], Orr [1981]

Data-oriented designData-oriented design Has never been as popular as action-oriented design With the rise of OOD, data-oriented design has largely

fallen out of fashion

So

ftw

are

En

gin

eeri

ng

SI3

34

51

Recap: Relationships Between UML DiagramsRecap: Relationships Between UML Diagrams