This month, I’d like to discuss one method of ensuring the correctness of an object-oriented program. Of course, it is difficult to ensure that a program is 100% correct, but we can state a program’s specifications and determine if the program meets those specifications. Design by Contract (or DbC for short) is a formal statement (or “contract”) of how code should function if supplied with the proper information. If the contract is met, the methods that call that code can rest assured that the code will work correctly. if the contract is not met, we can find out what went wrong and where it went wrong. REALbasic lacks direct support for DbC, but I’ll show you a way to add it to your programs.
This series is designed as a continuation of my previous RBLibrary article Beginning Object-Oriented Programming with REALbasic, so I would recommend reading it.