术语“重复不变”和“重复正常”是什么意思?

发布于 2024-12-06 14:45:17 字数 1436 浏览 5 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉城已无爱 2024-12-13 14:45:17

表示不变量是有关对象状态的条件。对于给定对象,条件始终可以假设为真,并且操作需要不违反它。

在 Deck 类中,表示不变量可能是牌组中始终有 52 张牌。因此,shuffle() 操作可以保证不会将任何牌掉落在地板上。这反过来意味着调用 shuffle() 或任何其他操作的人不需要检查之前和之后的卡片数量:他们保证它始终是 52。

A representation invariant is a condition concerning the state of an object. The condition can always be assumed to be true for a given object, and operations are required not to violate it.

In a Deck class, a representation invariant might be that there are always 52 Cards in the deck. A shuffle() operation is thus guaranteed not to drop any cards on the floor. Which in turn means that someone calling shuffle(), or indeed any other operation, does not need to check the number of cards before and after: they are guaranteed that it will always be 52.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文