26
Object Specification Moving towards a more precise specification of software

Object Specification Moving towards a more precise specification of software

  • View
    215

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Object Specification Moving towards a more precise specification of software

Object Specification

Moving towards a more precise specification of software

Page 2: Object Specification Moving towards a more precise specification of software

Sequence (object interaction) diagrams

• Provide detail on the interaction between objects and the division of responsibility between objects- which classes hold which operations.

• When this is clear we can then look at providing more detail on significant (or more complex) operations.

Page 3: Object Specification Moving towards a more precise specification of software
Page 4: Object Specification Moving towards a more precise specification of software
Page 5: Object Specification Moving towards a more precise specification of software

Operation specification

• describes the detailed behaviour of the system.

• adds detail and precision so that user can check if requirements are met.

• Provides more detail for software design and helps in coding.

Page 6: Object Specification Moving towards a more precise specification of software

Example : Black box specification ‘Contract’ describes the external interface of an object

and its signature.

• We know what goes in• We know what comes out• We know what the message does• We don’t know how it does it.

Balance

Getaccountbalance

Page 7: Object Specification Moving towards a more precise specification of software

Contracts

• Intent or purpose of the operation• Operation signature : parameters and return

type• Description of the logic• Other operations called• Events transmitted to other objects• Response to exceptions

Page 8: Object Specification Moving towards a more precise specification of software

Delay flight alters the flight duration by the number of minutes specified.

Get arrival time returns the time of arrival.

Why do we need to be specific here?

Examples from IBM Rational class diagrams

Page 9: Object Specification Moving towards a more precise specification of software

Non-algorithmic (declarative) Approaches• Describe the logic of the operation as a black

box.• Show Operation Signatures or message

protocols• useful where a structured decision has to be

made- the description is used to determine the conditions that determine the outcome.

• E.g. decision tables, pre and post conditions, OCL (Object Constraint Language )

Page 10: Object Specification Moving towards a more precise specification of software

Decision TablesA decision table is a matrix that shows the conditions under

which a decision is made, the actions which can result and how the two are related.

Steps in Drawing a Decision Table1. List all conditions2. List all possible actions3. Fill in true/false values4. Assign actions 5. Ensure all possibilities have been covered.

• These are useful for situations where there are many outcomes depending on various combinations of input conditions.

Page 11: Object Specification Moving towards a more precise specification of software

Decision Table example – register student on water safety

RULE 1 RULE 2 RULE 3

Conditions

Has student the prerequisite qualification?

Y N Y N

Is student old enough? Y Y N N

Action

Register Student x

Register on prerequisite (if qualified and old enough)

x x

Repeat or put on endurance training

x

Page 12: Object Specification Moving towards a more precise specification of software

Decision Table example – can player get out of jail?

RULE 1 RULE 2 RULE 3 RULE 4

Conditions

Has player get out of jail free card?

Y N N N

Have they had 3 turns? N Y N N

Have they paid £50? N N Y N

Action

Let out x x x

Keep in Jail x

Page 13: Object Specification Moving towards a more precise specification of software

Decision Table

RULE 1 RULE 2 RULE 3 RULE 4

Conditions

Actions

Page 14: Object Specification Moving towards a more precise specification of software

• Precondition : what is true/must be true before the method or operation is executed

• Postcondition: what is true/must be true after the method or operation is executed.

• Where have we seen pre and post conditions before?

Page 15: Object Specification Moving towards a more precise specification of software

Example : enrol(student, module)

Precondition• <student and module objects valid>

Postcondition• < enrolment object created>

Page 16: Object Specification Moving towards a more precise specification of software

Object Constraint Language (OCL)

This is used if a much more formal and precise specification is needed. This is a language with a strict syntax used to specify, for example, pre and post conditions.

Page 17: Object Specification Moving towards a more precise specification of software

• in some cases there may be a need to describe an object’s logic or internal behaviour- though this is essentially a design activity

Page 18: Object Specification Moving towards a more precise specification of software

Algorithmic Approaches

• Algorithm- describes the internal logic of a process or decision by breaking it down into small steps.

• Uses sequence, selection, iteration and recursion

Example Approaches • Structured English/pseudocode• Activity diagrams, flowcharts

Page 19: Object Specification Moving towards a more precise specification of software

Structured English

Operation: withdraw_cash (amount)

If amount <= bank balance Subtract amount from bank balance Otherwise Display bank balance Display error message.

Page 20: Object Specification Moving towards a more precise specification of software

PseudocodeIf amount <= bank balance { balance = balance – amount;

success =true; else{ Display bank balance Display error message Success = false}return(success)

Page 21: Object Specification Moving towards a more precise specification of software

Activity diagrams e.g. Make Booking

systemcustomer

Page 22: Object Specification Moving towards a more precise specification of software

Example: An operation in monopoly to check whether a player can buy a

hotelIf the player has the full colour set AND none of them are mortgagedAND the player has four houses on the propertyAND the player has enough money for one houseThey can exchange the four houses for a hotel.

If they have the full colour set AND none of them are mortgaged AND they have less than four houses, AND enough money for one house, they can buy a house.....

If they have the full colour set, .....

Use a decision table to lay out the rules more efficiently

Page 23: Object Specification Moving towards a more precise specification of software

An operation is required to calculate a fine for an overdue DVD loaned by a video shop.

• The number of days overdue is calculated by subtracting current date from the due date.

• If the DVD is a category A ( current top 10), then the fine is €1 per night for the first 15 nights, and thereafter the full cost of the DVD will be charged.

• If the DVD is a category B, the fine is €0.50 per night for the first 20 nights and thereafter the full cost of the DVD will be charged.

• For DVDs of category C (old DVDs) the charge is €0.30 per night for the first 20 nights and after that there is no further charge.

Page 24: Object Specification Moving towards a more precise specification of software

class loan{

dvd id : intcategory : charloan date : datedue date : date

float calculate_fine(todaysdate:date)}

Page 25: Object Specification Moving towards a more precise specification of software

Operation calculate fine

1. Draw a decision table2. Write some pseudocode or structured english3. Draw an activity diagram

Page 26: Object Specification Moving towards a more precise specification of software

Conditions

Category A Y Y N N N N

Category B N N Y Y N N

Category C N N N N Y Y

>15 nights overdue N Y N N N Y

>20 nights overdue N - N Y N Y

Actions

Charge cost of DVD * *

Charge 0.30 *20 *

Charge €1 per night *

Charge €0.50 per night *

Charge €0.30 per night *