Object Specification Moving towards a more precise specification of software.
-
date post
22-Dec-2015 -
Category
Documents
-
view
215 -
download
1
Transcript of Object Specification Moving towards a more precise specification of software.
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.
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.
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
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
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
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 )
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.
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
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
Decision Table
RULE 1 RULE 2 RULE 3 RULE 4
Conditions
Actions
• 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?
Example : enrol(student, module)
Precondition• <student and module objects valid>
Postcondition• < enrolment object created>
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.
• in some cases there may be a need to describe an object’s logic or internal behaviour- though this is essentially a design activity
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
Structured English
Operation: withdraw_cash (amount)
If amount <= bank balance Subtract amount from bank balance Otherwise Display bank balance Display error message.
PseudocodeIf amount <= bank balance { balance = balance – amount;
success =true; else{ Display bank balance Display error message Success = false}return(success)
Activity diagrams e.g. Make Booking
systemcustomer
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
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.
class loan{
dvd id : intcategory : charloan date : datedue date : date
float calculate_fine(todaysdate:date)}
Operation calculate fine
1. Draw a decision table2. Write some pseudocode or structured english3. Draw an activity diagram
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 *