Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

abstraction

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?

like image 405
xonegirlz Avatar asked Sep 28 '11 03:09

xonegirlz


People also ask

What is the rep invariant?

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.

What is concrete state space concrete invariant?

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.

What does it mean for an object to have invariants and why does one need to worry about them?

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.

What is the abstraction function?

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.


1 Answers

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.

like image 155
Uffe Avatar answered Oct 17 '22 08:10

Uffe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!