按合同设计为您工作吗? [英] Does Design By Contract Work For You?

查看:123
本文介绍了按合同设计为您工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你是否按专业的合同使用设计?这是您从项目开始就要做的事情,还是可以改变齿轮并开始将其纳入软件开发生命周期?你发现什么是设计方法的利弊?



我遇到了按合同设计方法在研究生课程中。在学术界,似乎是一个非常有用的技术。但是我目前没有使用专业的按合同设计,而且我不知道任何其他正在使用它的开发人员。从SO人群中了解其实际使用情况可能会很好。

解决方案

我不能非常推荐它。如果您有一套套件,可以采用内联文档合同规范,如下所示:

  // @returns null iff x = 0 
public foo(int x){
...
}

并将其转换为生成的单元测试,如下所示:

  public test_foo_returns_null_iff_x_equals_0(){
assertNull foo 0);
}

这样,你可以看到你正在运行的测试,但是自动生成生成的测试不应该被检查到源代码控制,顺便说一句。


Do you use Design by Contract professionally? Is it something you have to do from the beginning of a project, or can you change gears and start to incorporate it into your software development lifecycle? What have you found to be the pros/cons of the design approach?

I came across the Design by Contract approach in a grad school course. In the academic setting, it seemed to be a pretty useful technique. But I don't currently use Design by Contract professionally, and I don't know any other developers that are using it. It would be good to hear about its actual usage from the SO crowd.

解决方案

I can't recommend it highly enough. It's particularly nice if you have a suite that takes inline documentation contract specifications, like so:

// @returns null iff x = 0
public foo(int x) {
  ...
}

and turns them into generated unit tests, like so:

public test_foo_returns_null_iff_x_equals_0() {
  assertNull foo(0);
}

That way, you can actually see the tests you're running, but they're auto-generated. Generated tests shouldn't be checked into source control, by the way.

这篇关于按合同设计为您工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆