Title: Primitive data type
1Primitive data type
- Characterize data into different kinds for
convenience
- bit
- byte
- integer
- ascii
- character
- array
- string
- real
- record
operations ? Objects
2Abstraction (primitive date types are already
abstracted from bits 0/1)
- A tool (concept) to manage complexity
- Hide irrelevant details focus on the features
needed - Examples
- File deletion using icons
- The brakes on a car
- Television remote
3Data Type
- Specification View of a data type
- Data values
- Operations defined on those values
- Abstract Data Type (ADT) use of abstraction!
- Implementation View of a data type
- Language-specific representation for the values
- Implementation of the operations
- ? Implementation of an ADT
4Abstract Data Type (ADT)
Abstract model of Priority Queues
(Specification View)
insert one item
Priority Queue
Get the one with the highest priority
the minimum one (or maximum)
a black box
5Abstract Data Type (ADT)
Abstract model of Priority Queues
(Implementation View)
insert one item
Binary Search Tree or Binary Heap?
Get the one with the highest priority
the minimum one (or maximum)
6The Java Collections Framework (JCF)
UML Class Diagram
7Collection Operations
Most collections support the same operations, but
may give them different names.
- Add an element
- Remove an element
- Replace an element
- Retrieve an element
- Determine if a collection contains an element
- Get the collections size
- Determine if a collection is empty
- Traverse a collection
- Determine if two collections are equal
- Clone a collection
- Serialize a collection
8A collection List
What does a user of a List need to know about it?
Its behavior as described in its API and related
documentation.
Possible implementations of the List ADT. The
implementation details are hidden from the user
of the List, who relies on the Lists public
interface.
9Abstraction A Collection Example
A List has many uses. A client (user) accesses a
List through its public interface (API) without
any knowledge of how the List is implemented.
10Each object has 3 characteristics
- State
- the values of the attributes are consistent with
the classs invariants - Stable state the values of the attributes are
consistent with the classs invariants - Behavior
- the set of operations visible in the objects
API (Application Programmer Interface) defines
the kinds of messages the object can receive - Constructor put the object in an initial stable
state - Accessor retrieve state information may be
synthesized - Mutator change the state of the object
(consistent with the invariants) - ? Identity unique for each object
11Specifying an ADT
A rectangle example
Rectangle
Description A rectangle is a four-sided shape in
which opposite sides are parallel and equal in
size. The length of a side must be greater than
0. A rectangle has four right angles.
ADT description A brief description of the new
type.
Invariants 1. Opposite sides are of equal
size. 2. Length and height must be greater than
0.
ADT invariants Characteristics that must always
be true of an instance of this type.
12Specifying an ADT
A rectangle example
Attributes DEFAULT_SIZE a constant, the default
size for the dimensions length size of the
top and bottom sides height size of the
left and right sides surface area the
surface area of the rectangle perimeter the
perimeter of this rectangle
ADT attributes Represent the state of an
instance of the ADT.
13Specifying an ADT
A rectangle example
Operations constructor() constructor( length,
height ) getLength() setLength( newLength
) getSurfaceArea()
ADT operations Define the behavior of the ADT
and the interface available to clients.
14Rectangle ADT
Operations constructor() pre-condition
none responsibilities default
constructorcreates a rectangle with length and
height set to DEFAULT_SIZE post-condition the
rectangle is initialized to the default
values returns nothing constructor( length,
height ) pre-condition none responsibilities
creates a rectangle with length length and
height height if a dimension is invalid, the
default size is used post-condition the
rectangle is initialized to client-supplied
values, if valid, or the default values
otherwise returns nothing
15Rectangle ADT
getLength() pre-condition none responsibilities
returns this rectangles length post-condition
the rectangle is unchanged returns the length
of the rectangle setLength( newLength
) pre-condition none responsibilities resets
length to newLength if newLength is valid
otherwise does nothing post-condition
rectangles length field is updated if newLength
is valid returns nothing getSurfaceArea() pre-c
ondition none operation compute the surface
area of this rectangle post-condition the
rectangle is unchanged returns the surface area
of the rectangle
16UML Class Diagrams