Data Abstraction
- In our main program, we don't really know how the bignum is implementd.
- Is this good?
- Portions of programs can be developed in parallel
- Underlying details can be changed without changing the program.
- (Think about reversing how the digits are stored)
- Or any other change in how we do things...
- It turns out that we often want to do this.
- Data Abstraction is the separation of a data type's logical
properties form its implementation.
- For example: integers
- High Abstraction:
- Integers represent whole numbers {..., -3, -2, -1, 0, 1, 2, 3, ...}
- They support the operations +,-, comparison, *, and /
- Implementation:
- an integer is represented by 32 bits
- integers are stored as a two's compliment number
- To add two integers
- align least significant bit
- add bits, with a carry to the next most significant bit
- If the final carry out does not equal the carry in, overflow.
- We talk of a specification, which tells us what a function or a data type does.
- We also have an implementation, which is the structure or algorithm to accomplish the specification.
- An Abstract Data Type (ADT) is a data type whose properties
(domain and operations) are specified independently of any implementation.
- Think about our bignum package again
- The abstraction
- An signed integer up to 100 digits
- Operations
- addition subtraction
- multiplication
- compare, swap
- I/O
- The implementation
- Let's try another, how about a counter (like a turnstile)
- Often we have the following catigories of routnes
- Constructors
- Transformers
- Observers
- Iterators