4 Design Principles I X 4

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Process Phase Affected by This Chapter

Chapter 4 Design Principles I Correctness and Robustness

Requirements Analysis Design Framework Architecture Detailed Design


Key: = less affected

Implementation

COMP 7700 Correctness and Robustness

COMP 7700 Correctness and Robustness


Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Sufficient Designs: Terminology and Rationale Minimum goal: A design sufficient to implement the requirements. a correct design

Key Concept: Correctness


It follows that

Sometimes called

Goal: That each artifact satisfies designated requirements, and that together they satisfy all of the applications requirements.

the design must be entirely understandable A common way to achieve this is to make the design very modular

COMP 7700 Correctness and Robustness


Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

COMP 7700 Correctness and Robustness


Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Invariants for Class Automobile 1) mileage > 0 Key Concept: Correctness by Informal Methods Simplify and modularize designs until they convince. 2) mileage < 1000000

-- with variables mileage, VehicleID, value, originalPrice, and type:

3) vehicleID has at least 8 characters 4) value >= -300 ($300 is the disposal cost of a worthless automobile) 5) originalPrice >= 0 6) ( type == REGULAR && value <= originalPrice ) || ( type == VINTAGE && value >= originalPrice )

COMP 7700 Correctness and Robustness


Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

COMP 7700 Correctness and Robustness


Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Introducing Interfaces 1 of 2

Shipment setVehicle() perishable() getWidth() printRoute() describeType() getLength() getDuration() setType()

Introducing Interfaces 2 of 2
Original form Shipment setVehicle() perishable() getWidth() printRoute() describeType() getLength() getDuration() setType()
7

Dimensions getWidth() getLength() getWeight()

TransportationMeans getDuration() setVehicle() printRoute()

GoodsType describeType() setType() perishable()

Shipment Forms using interfaces Dimensions Shipment TransportationMeans GoodsType


COMP 7700 Correctness and Robustness
8

COMP 7700 Correctness and Robustness


Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Package Interfaces
purchases Furniture Clothing Appliance
singleton

chatServer Conversation

Example of Package Interfaces


Conversationservices Participantservices

Pricing Selection ClothingTryout

ConversationManager ServerComm chatClient Display Messagereception ClientComm Bill Financial


10

PurchasesIF

billing Accounting
COMP 7700 Correctness and Robustness
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

COMP 7700 Correctness and Robustness


Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Domain vs. Non-Domain Classes


Domain classes: Particular to the application
Examples: BankCustomer, BankTransaction, Teller

Key Concept: Interfaces -- collections of function prototypes: Make designs more understandable.

Typically not GUI classes Sufficient to classify all requirements (see chapter xx)

Non-Domain classes: Generic


Examples: abstract classes, utility classes Arise from design and implementation considerations

COMP 7700 Correctness and Robustness


Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

11

COMP 7700 Correctness and Robustness


Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

12

Alternative Modularizations Alternative 1 mechanics

Application tracking trajectory of rocket carrying orbit-bound satellite into position Alternative 2 control

Improving Robustness: Sources of Errors


Protection from faulty Input
o o User input Input, not from user
Data communication Function calls made by other applications

position trajectory ground control weather onBoardNavigation


COMP 7700 Correctness and Robustness
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Protection from developer error


Faulty design Faulty implementation

13

COMP 7700 Correctness and Robustness


Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

14

Constraints on Parameters
Example:
int computeArea( int aLength, int aBreadth ) { }

Capture parameter constraints in classes if feasible


int computeArea( RectangleDimension a RectangleDimension )

Specify all parameter constraints in method comments


aLength > 0 and aBreadth > 0 and aLength >= aBreadth

Key Concept: Robustness -- is promoted by verifying data values before using them.

Callers obey explicit requirements on parameters


o Problem is method programmers have no control over callers

Check constraints first within the method code


if( aLength <= 0 ) Throw exception if this is a predictable occurrence Otherwise abort if possible Otherwise return default if it makes sense in context
And generate warning or log to a file COMP 7700 Correctness and Robustness
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

15

COMP 7700 Correctness and Robustness


Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

16

Wrapping Parameters Replace int computeArea( int aLength, int aBreadth ) {..} with int computeArea( Rectangle aRectangle ) {..} -- where class Rectangle { Rectangle( int aLength, int aBreadth ) { if( aLength > 0 ) this.length = aLength; else .. } }COMP 7700 Correctness and Robustness
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Key Concept: Robustness -- is promoted by enforcing intentions.

17

COMP 7700 Correctness and Robustness


Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

18

How Much Design Detail Before Initial Coding? 100%

Video Store Application: Sufficient Classes? Video CheckOutDurationDisplay CheckOutDisplay RegisterNewVideoDisplay

Recommended % of design detail before starting to code

Inexperienced designer

Customer BarCodeReader

Experienced designer 0%

Diminishing ability of designer to envisage consequences of design decision. Very complex


19

COMP 7700 Correctness and Robustness Very simple Type of application

COMP 7700 Correctness and Robustness


Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

20

Summary of This Chapter

o o

Correctness of a Design or Code


Supports the requirements In general, many correct designs exist

Robustness of a Design or Code


Absorbs errors
o o -- of the user -- of developers

COMP 7700 Correctness and Robustness


Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

21

You might also like