Contract

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Contract

Nick Lee
Could somebody elaborate what exactly does the book mean whenever it says "contract". I see it quite often and suspect it is something important but don't fully grasp its meaning when used in this context (where its dictionary definition doesn't really help).

Thanks in advance.
Reply | Threaded
Open this post in threaded view
|

Re: Contract

robotron
They are referring to a well-described, published way some facility can be used. In order for the facility to be used you must be familiar with its interface.

For example, let's talk a bit about the ALU.
ALU has a certain interface: 6 bits for control, couple of bits on the input, couple of bits on the output (can't recall exact numbers right now). You can use that interface to input some values and use the ALU.

Say that you supply a specific combination of control and input bits to the ALU - a specific operation will be performed: e.g. 10000101010 means A+D (the combination is made up).

That is contract. When you can reliably know what will happen on the output when you provide some input in a defined manner using defined interfaces.

Its difficult for you to go around probing each combination by hand until you get it right. In order for you to be able to use the ALU effectively its creators have published all the various combinations of bits through which you can use the it, and all the various outputs that arise from the given input combinations.

Reply | Threaded
Open this post in threaded view
|

Re: Contract

Nick Lee
Hi there thanks for the reply!

I think I understand what you are saying. So in other words the word "contract" used in this context can be used interchangeably as synonyms with "interface" or "abstraction" or "API"?
Reply | Threaded
Open this post in threaded view
|

Re: Contract

robotron
The way I understand it from the book and from my experience, yes.