我将在埃夫勒撰写这一例子,使之简单易懂。
my_code
-- Calls the `do_something routine
do
set_table ("my_table")
do_something
end
do_something
-- Something to do
require
valid_table: is_valid_table (table_name)
do
sql_list := execute_sql_on_table (table_name)
ensure
has_result: sql_list.count > 0
end
sql_list: ARRAYED_LIST [STUFF]
table_name: STRING
set_table (a_name: STRING)
-- Set `table_name to `a_name
require
has_name: not a_name.is_empty
valid_table: is_valid_table (a_name)
do
table_name := a_name
ensure
table_name_set: table_name.same_string (a_name)
end
delete_table (a_name: STRING)
-- Delete `a_name from the database.
require
valid_table: is_valid_table (a_name)
do
execute_sql ("DROP TABLE " + a_name)
ensure
table_gone: not is_valid_table (a_name)
end
- The feature `do_something is a command, where the array sql_list is to be loaded with STUFF from the table "my_table".
- The precondition contract on
do_something makes it the responsibility of the client
my_code to provide table_name before making the call to
do_something .
- In return, the post-condition ensure contract makes it the responsibility of the supplier
do_something fill the array
sql_list with instances of STUFF.
- The feature `sql_list is a query, returning a reference pointer to an array of STUFF.
- Similarly, the feature
table_name is a query returning a reference pointer to a STRING, which is set with a "setter" command called
set_table .
在这种情况下,“合同”是指确保适当区分关切,由谁负责上述小型法典。 《刑法》中明显缺乏TRY-CATCH的建筑。 在这种情况下,数据来源预计将具有“米-表”。 合同的存在意味着,如果合同失败,软件将产生例外。 要求失败的称呼器被打破,而供应商的定购后点失败。
最后,这部法典显示了明确的开端和合同规定的质量保证的应用。 因此,可以回答原来的问题:
“我们如何理解指挥吗? ql指挥(ex:真空删除(可下载))是什么? 我们如何知道这一表格是否存在?”
While it might be true that a call to delete_table ("my_table") might be injected into some ancestor or might happen on another thread, this is what the contracts are for in do_something . As long as those contracts stand guard over calls to
do_something , the process will be appropriately handled. An injected call to `delete_table will simply cause the contract to fail.
所有这一切都假定,只有NOT OK ,DROP TABLE “my_table”,而这样做是不幸的。 然而,如果它变成了DROP TABLE“my_table”的基数,那么需要一个再工业机制或其他“handler”来管理这一使用案例,而上述准则将不起作用。