开发者

what does the term rep-invariant and rep ok means? [closed]

开发者 https://www.devze.com 2023-04-08 17:20 出处:网络
Closed. This question needs to be more focused. It is not currently accepting answers. 开发者_Python百科
Closed. This question needs to be more focused. It is not currently accepting answers.
开发者_Python百科

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 6 years ago.

Improve this question

I heard this a lot when talking about software engineering and abstract data types, what does this do? Can anyone give me a concrete example of this concept?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号