Up to this point we have modeled the static structure
of a system and classes in the system object model and object
model. We have identified system operations and object operations.
We have modeled the dynamic stimulus response behavior of the
system and objects in the system in the system dynamic model and
the dynamic model in which operations are invoked. Now we must
look at each operation and define the transformation of inputs
to outputs in the system functional model and the functional model.
We desire to define the transformation in terms of computation,
algorithms, and formulas.
The functional model describes transformations of
object values in operations from an input to an output. Several
simple operations which transform object values are shown below.
A transformation could be described as follows:
- a table showing the mapping from one object value to another,
- a formula or equations showing the relationship between an input object value and an output object value,
- a text description of the transformation.
For example, one of the simplest transformations
is the increment transformation shown above. A table describing
the increment transformation would have the entries: 1, 2; 2,
3; 3, 4; etc. The table shows the input and output values. An
equation describing the increment transformation would be "aNumber
= aNumber + 1". A text description of the increment transformation
would be "add 1 to the input value".
A transformation may change the value of an atomic
object (1, 4.2, 'c'), a structured object (student1), or a collection
object (aListOfStudents). A transformation may change the value
of atomic object, the value of an attribute of a structured object,
or the value of a member of a collection object. The term value
may refer to a literal value, e.g. 1, 4.2, or 'c' or to a reference
value, e.g. an object ID such as student1.
A transformation may occur in the following forms of operations:
- A system operation is an operation for the system as a whole. A system operation receives an input object and changes an output object. A system operation may access or modify a system attribute. A sample system operation for a bank ATM system is "withdrawCash".
- A class operation is an operation defined in a class that accesses or modifies a class attribute value. A class operation affects all objects of the class. When a class operation is invoked to change a class attribute value, all objects of the class share this attribute value.
- An object operation is an operation defined
in a class that accesses or modifies an attribute value. An operation
may receive an input parameter and may send an output parameter.
A sample operation in a bank ATM Account class is "updateAccountBalance".
This operation modifies the attribute "accountBalance".
In this section we will progress from the system
functional model to the functional model as shown below.
System Functional Model Functional Model
In the System Functional Model we specify all the system operations including the operation input objects (parameters), transformation, and output objects as shown below.
The steps to specify system operations is as follows:
Step 1. Start with the System Object Model and System
Dynamic Model to identity all system operations.
Step 2. Specify each system operation in the CASE
tool that has a transformation of object values in the operation
input specification form presented earlier. In the form, state
the system operation name, input objects (parameters), transformation,
output objects (return values). Optionally, state the system operation
preconditions, postconditions, and exceptions.
Step 3. Create the system operation table and system
operation report in the CASE tool by running a report script or
selecting the appropriate report.
Step 4. Check and update consistency with other models,
e.g. the system object model and system dynamic model. Check all
diagrams and text specifications for the consistent spelling,
capitalization, and meaning of all names.
For the Car Simulation System, we can see the system operations on the system diagram (OMT format) shown below. The system interaction diagram for the Car Simulation System was previously shown.
The following is a the system operation table for
the Car Simulation System. C++ data types are used to document
the input parameters and return types. The sample CASE tool table
script is TABOPER.SCT.
| System Operation Name | Input Parameters | Transformation | Return Type |
| start | gasQuantity = gasQuantity - .1; | void | |
| operate | int aSpeed | gasQuantity = gasQuantity - .1; speed = aSpeed; | void |
| stop | speed = 0; | void | |
| makePhoneCall | long aNumber | void | |
| receivePhoneCall | long aNumber | void | |
| addPassenger | Passenger aPassenger | void | |
| removePassenger | Passenger aPassenger | void |
The operation table generation script (TABOPER.SCT) is shown below.
SCRIPT_NOREPEAT_HEADER_BEGIN
Class Name, Operation Name, Input Parameters, Transformation, Return Type SCRIPT_NOREPEAT_HEADER_END
[CLASS_NAME, OPERATION_NAME, CPP_OPERATION_PARAMETERS, OPERATION_TRANSFORMATION, OPERATION_RETURN_TYPE]
Once we have completed the system models, the object
model and the dynamic model, we can specify all operations in
the functional model. The functional model is the set of transformations
and correctness assertions, e.g. preconditions, postconditions,
and invariants. A transformation is a description of how an object
value may be correctly changed in a formula, expression, table,
etc. An assertion is a rule or expression for correctness, e.g.
a value must always be greater than zero. An operation precondition
is a rule or expression that must be satisfied before the execution
of an operation for correct results. An operation postcondition
is a rule or expression that is satisfied upon the correct execution
of an operation. An invariant is a general rule or expression
that must be satisfied at all times by all applicable operations.
An exception is an abnormal execution error condition, e.g. listFullError
or noGasError that may be raised to signal that an operation cannot
be executed correctly. In the car example, the start operation
has a precondition and postcondition. The precondition for the
start operation is that the gasQuantity must be greater than zero.
The postcondition of the start operation is the verification that
the correct value of gasQuantity has been computed.. The invariant
is that gasQuantity must be equal to or greater than zero and
equal to or less than the maximumGasQuantity. In the functional
model, we update class specifications with transformations and
correctness assertions.
Key aspects of an operation are shown below. Only
input and output parameters are shown in the diagram below. An
operation may access or update attribute values or global objects.
In the Car class, there is transformation in the start operation. The transformation is represented by the formula "gasQuantity = gasQuantity - .1". In this example, when the start operation is invoked, then there is a transformation of the attribute gasQuantity. Specifically, the value of the gasQuantity is changed. When the start operation is invoked the value of the gasQuantity is reduced. There are no input or output parameters for this operation. In the functional model we identify, examine, and describe operations in which there is a transformation of objects.
The key aspects of the start operation are graphically
shown below. It shows that there are no object inputs or outputs
(parameters), the precondition of "gasQuantity > 0",
the postcondition of "gasQuantity < oldGasQuantity + 1",
the transformation formula, and the exceptions noGasError and
calculationError.
The functional model is important for many reasons.
First, transformations (operations) are important because they
accomplish work required by the system requirements. Second, identifying
transformations (operations) leads to identifying the system input
objects, system output objects, and system operations. Third,
identifying operation preconditions, postconditions, and exceptions
help create highly reliable operations. Fourth, operations are
implemented by coding the transformation equations, preconditions,
postconditions, and exceptions.
In the functional model we specify transformations
of objects in operations. In the functional model, we specify
how objects are transformed in a system. Follow these steps.
Step 1. Start with the system models, object model,
and the dynamic model to identify all operations.
Step 2. Specify each modifier operation that transforms
object values in the CASE tool operation specification form. Update
operation specifications with transformations, e.g. formulas,
expressions, equations and correctness assertions, e.g. preconditions,
postconditions, and invariants for each operation.
Step 3. Create the operation table and operation
report by running a CASE tool report script or selecting the appropriate
report.
Step 4. Check and update consistency with other models,
e.g. the object model and dynamic model. Check all diagrams and
text specifications for the consistent spelling, capitalization,
and meaning of all names.
Step 5. Update the C++ source code to reflect the transformations and correctness assertions. Compile and execute the program.
After we have identified the class and object operations,
we can specify the operations by filling in the CASE tool operation
specification form shown earlier. To describe class and object
operations, specify transformations and correctness assertions.
The steps to update the class specification for transformations
and correctness assertions are listed below.
>> Run the CASE tool from Windows
>> Double click on a class
>> Select "Operation Specification"
>> Enter transformations and correctness assertions in the operation specification form
>> Select "Generate - Generate Report"
to create the operation table and operation report as shown below
A sample detailed operation table shows the operations
in the system with their inputs, preconditions, transformations,
postconditions, and outputs. A sample operation table showing
three operations for the Car class are shown below. The sample
CASE tool script is TABOPPRE.SCT.
| Class Name | Operation Name | Input Para-meters | Precondition
/Exception | Transformation | Postcondition
/Exception | Return Type |
| Car | start | gasQuantity > 0/noGasError | gasQuantity = gasQuantity - .1 | gasQuantity < oldGasQuantity
/calculationError | void | |
| Car | operate | int aSpeed | aSpeed <= maxSpeed /speedHighError |
gasQuantity = gasQuantity - .1; s rpm = 50 * aSpeed peed = aSpeed | gasQuantity < oldGasQuantity /calculationError; speed == aSpeed /calculationError | void |
| Car | stop | speed = 0 | speed == 0/stopError | void |
The sample detailed operation table (TABOPPRE.SCT) is shown below.
SCRIPT_NOREPEAT_HEADER_BEGIN
Class Name, Operation Name, Input Parameters, Precondition/Exception, Transformation, Postcondition/Exception, Return Type SCRIPT_NOREPEAT_HEADER_END
[CLASS_NAME, OPERATION_NAME, CPP_OPERATION_PARAMETERS, OPERATION_PRECONDITION,
OPERATION_TRANSFORMATION, OPERATION_POSTCONDITION, OPERATION_RETURN_TYPE]
A sample operation report for the Car class start
operation is shown below.
- Class name: Car
- Operation name: start
- Return type or class: none - void
- Input parameter type/class and name: none
- Access: public
- Type of operation: concrete
- Category of operation: modifier
- Implementation language feature: C++ function
- Transformation: gasQuantity = gasQuantity - .1
- Precondition: gasQuantity > 0 else noGasError
- Postcondition: gasQuantity < oldGasQuantity else calculationError
- Exceptions: noGasError and calculationError
- Applicable Invariant: gasQuantity must be equal to or greater than 0 and equal to or less than maxGasQuantity
- Concurrency: Sequential
- Time: Low
- Space: Low
- Description:
start operation simulates the start of a car.
The following is the structure of a function definition
with the exception declarations, precondition check, transformation,
and postcondition check. Compare this structure with the start
function shown in the C++
returnType className::functionName (argument list) throw (exceptionTypes)
{ exceptionType exceptionNameForPrecondition; //exception declaration
exceptionType exceptionNameForPostcondition; //exception declaration
if (precondition check) //precondition check
function statements for transformation; //transformation
else throw exceptionName; //throw exception
if (postcondition check) return; //postcondition check
else throw calculationError; //throw exception
}
The C++ source code is shown below that implements
the start operation with correctness assertions.
//////////////////////////////////car.h file//////////////////////
#ifndef __CAR_H
#define __CAR_H
#include <CString.h>
class Car
{ float gasQuantity;
public:
Car () { gasQuantity = 0; }
void start () throw (string, char);
};
#endif
///////////////////////////////car.cpp file/////////////////////////
#include "Car.h"
void Car::start() throw (string, char)
{ string noGasError; //exception declaration
char calculationError; //exception declaration
float oldGasQuantity; //required for postcondition check
if (gasQuantity > 0) //precondition check
{ oldGasQuantity = gasQuantity; //saves oldGasQuantity
gasQuantity = (gasQuantity - .1); //transformation
}
else throw noGasError;
if (gasQuantity < oldGasQuantity) return; //postcondition check
else throw calculationError;
}
///////////////////////////////main.cpp file///////////////////////////
#include "Car.h"
#include <CString.h>
#include <iostream.h>
int main ()
{
Car car1;
try {
car1.start(); }
catch (string noGasQuantity) { cout << "No Gas Error"; }
catch (char calculationError) { cout << "Calculation Error"; }
catch (...) { cout << "Unknown Error"; }
return 0;
}
////////////////////////Sample Output///////////////////////////
//No Gas Error
The functional model describes transformations of object values in operations from input to output. For the system as a whole, we describe input objects, output objects, and system operations (transformations). Typically, a system operation transforms (changes) an input object into an output object. For classes, we describe class and object operations. For each operation we describe the operation transformation, preconditions, postconditions, and exceptions.