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?
The rep invariant specifies legal values of the representation, and should be checked at runtime with checkRep() . The abstraction function maps a concrete representation to the abstract value it represents.
The concrete variables are the axes of a concrete state space. In the dynamic array example, the axes of the concrete state space are a and len. The linking invariant links points in the concrete state space with points in the abstract state space. For example s = [42,13] is a point in the abstract state space.
Invariant, quite literally, means something that does not change or vary. In the context of computer programming, it can be seen as a set of assumptions a piece of code takes before it is able to perform any computation of importance.
An abstraction function maps a state of the concrete machine to a state of the abstract machine. It explains how to interpret each state of the concrete machine as a state of the abstract machine.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With