SIBERSALDIRI.COM · FOCUSED LESSON
What you will learn
- Explain the relationship between prerequisite and Controlled change.
- “What status should the failed transaction leave?” To give a reasoned answer to the question.
- Changing the example and comparing expected and observed behavior.
How it works and where the trust boundary lies
For example, a limited counter should not allow the value to exceed the upper limit. It is not enough to simply leave control to the interface; The actual method that changes the field must preserve the rule. Giving a mutable internal reference or uncontrolled setter opens the way to get around the same rule. Also design how the error result will be communicated to the caller.
Worked example
The following passage makes the concept visible. Evaluate samples containing commands or code in your own separate testing environment, not in the production system. Architectural diagrams and policy examples are not executable programs.
class Bounded {
int value_{0};
public:
bool add(int delta){
if(delta < 0 || delta > 100-value_) return false;
value_ += delta; return true;
}
};Expected result and interpretation
The total remains in the range 0-100; The rejected transaction does not change the status.
Compare the scenarios
| Status | Recommended approach | Why? |
|---|---|---|
| 99 + 1 | acceptance | Equals upper limit |
| 99 + 2 | Rejection and no change | The limit is crossed |
| 0 + negative | Ret | It is against the auction contract |
Practice task
Test the cases of increasing by 2 from 99 and increasing by -1 from 0.
- Write down the expected outcome and acceptance condition before the action.
- Change a single variable; Record the observation and the medium you used.
- Evaluate the result with the comparison table above. Explain which assumption might be wrong if it does not fit.
Common mistake and how to correct it
Do not change the field before the unsuccessful operation and then return an error.
Test your understanding
What status should the failed transaction leave?
Answer explained: According to the defined error contract, the object must remain valid and understandable.
Continue with related lessons
- C++ access modifiers: Interface and internal detail
- C++ Inheritance: Preserving the Subtype Contract
- C++ Constructors: Creating Valid Objects
- C++ polymorphism: Behavior via interface
Technical reference
The explanation and examples of this course have been re-prepared for the academy. The link below is a technical reference to verify details of the technology or security approach used.
