Dynamic Constraints
Rules that describe how business concepts and
their relationships are affected by the operations of components.
Types of dynamic constraints
-
Invariants
-
A logical statement associated with an interface that a component assumes is
always true.
-
Ensure that component implementation will not invalidate the invariants
defined by the interface.
-
OCL representation for invariant:
“inv logical
statement”
-
Preconditions
-
A logical statement associated with a method in an interface that must be true
before that method can be invoked.
-
Client code should make sure that the precondition is true before it invokes
the method.
-
Incase, the client fails to make such a check, the component should gracefully
exit using Exceptions.
-
OCL representation for precondition:
“pre logical statement”
-
Postconditions
-
A logical statement associated with a method in an interface that must be true
after that method is invoked.
-
Component is responsible for ensuring postconditions of its interface methods.
-
Postcondition can refer to the component state or any of the method
parameters.
-
To refer to previous value of the component state or method parameter, it uses
@pre modifier.
-
OCL representation for postcondition:
“post logical
statement”