Views of Data – nouns of programming world Data

advertisement
Views of Data
Data – nouns of programming world


the objects that are manipulated
information that is processed
Humans like to group information
Classes, arrays
 Lists, stacks, etc.

Data Abstraction

View the data the way we want to (not the
way computer does)
Data Abstraction
Abstract – can be scary, but you’ve already
been doing that
Example: Integer



you view in a higher level than a computer (which
uses bits, two’s complement notation)
All you need to know is what is an integer and
what operations are allowed on them
The int type is encapsulated (surrounded by a nice
neat package to manipulate it)
Data encapsulation
Means the physical representation of data is
surrounded, the user doesn’t see the
implementation, but deals with data only in
terms of its logical picture (or abstraction)
Separations of the representation of data
from the applications that use the data at a
logical level; a programming language feature
that enforces information hiding
Abstract Data Type (ADT)
A data type whose properties (domain
and operations) are specified
independently of any particular
implementation.
Data Structures
A collection of data elements whose
organization is characterized by
accessing operations that are used to
store and retrieve the individual data
elements
The concrete implementation of the
composite data members in an abstract
data type
Features of ADTs
Data structures can be decomposed
into their component elements
Component elements can be “arranged”
in a way that affects their access
Both arrangement and way accessed
are encapsulated.
Example: library
Views
Logical (abstract) – What is ADT and
what are its operations
(Application) – Use them
Physical (concrete) or implementation –
How they are represented and how
they work.
ALSO THE ORDER WE’’LL STUDY THE ADTs
Information Hiding in ADTs
Separating class declaration/definition in .h and
.cpp files aids information hiding (as well as
using private)
1.
2.
Clients – access to info needed to use class
and nothing more
Implementer – access to info needed to
implement the module and nothing more
Advantages to Information
Hiding
Client
1.
2.
Easier to understand
Protected against inadvertently using
implementation detail that may change
Implementer
1.
2.
Can freely modify representation of type or
implementation of operation (client’s code will
still work)
Implementation protected from erroneous use
by client
Categories of ADT operations
Constructors – bring into existence
Transformers (mutators) – change the
state
Observers – predicates, accessor or
selector functions, summary functions
Iterators – process all the components
Download