TDD,DDD和封装 [英] TDD, DDD and Encapsulation

查看:135
本文介绍了TDD,DDD和封装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过几年后的坏习惯在我工作的地方,从'建筑师'传世认为必须有一个更好的办法,我最近一直在读围绕TDD和DDD和我想的原则和做法将是我们写的软件的复杂性非常合适。

After several years of following the bad practice handed down from 'architects' at my place of work and thinking that there must be a better way, I've recently been reading up around TDD and DDD and I think the principles and practices would be a great fit for the complexity of the software we write.

然而,许多TDD的样品我见过调用域对象的方法,然后测试性能对象,以确保正确执行的行为。

However, many of the TDD samples I have seen call a method on the domain object and then test properties of the object to ensure the behaviour executed correctly.

在另一方面,一些尊敬的业内人士(Greg Young的最明显的因此与他的CQRS会谈)主张充分通过删除所有的'干将'封装每个域对象。

On the other hand, several respected people in the industry (Greg Young most noticeably so with his talks on CQRS) advocate fully encapsulating each domain object by removing all the 'getters'.

所以我的问题是:如何做一个测试域对象的功能,如果它是被禁止检索其状态

My question therefore is: How does one test the functionality of a domain object if it is forbidden to retrieve its state?

我相信我失去了一些东西根本所以请随时给我打电话白痴和赐教 - 任何指导,将不胜感激。

I believe I am missing something fundamental so please feel free to call me an idiot and enlighten me - any guidance would be greatly appreciated.

推荐答案

什么你所描述的状态验证,其中你的域对象的状态断言。有被称为TDD的一个分支行为验证,利用Mock对象。

What you're describing is state verification wherein you Assert on the state of the domain object. There's a branch of TDD that is called behavior verification that utilizes Mock objects.

行为验证,您可以指定哪些方法应该被调用,如果你想,这方法不叫。

Behavior verification allows you to specify which methods should be called and if you want, which methods aren't called.

。看看这篇文章由Martin Fowler了解更多详情:嘲弄是不是存根

Look into this article by Martin Fowler for more details: Mocks Aren't Stubs.

这篇关于TDD,DDD和封装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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