Primitive data type - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

Primitive data type

Description:

The brakes on a car. Television remote. ITK 179. 3. Data Type. Specification View of ... the values of the attributes are consistent with the class's invariants ... – PowerPoint PPT presentation

Number of Views:21
Avg rating:3.0/5.0
Slides: 17
Provided by: ChungC7
Category:
Tags: data | primitive | type

less

Transcript and Presenter's Notes

Title: Primitive data type


1
Primitive data type
  • Characterize data into different kinds for
    convenience
  • bit
  • byte
  • integer
  • ascii
  • character
  • array
  • string
  • real
  • record

operations ? Objects
2
Abstraction (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

3
Data 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

4
Abstract 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
5
Abstract 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)
6
The Java Collections Framework (JCF)
UML Class Diagram
7
Collection 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

8
A 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.
9
Abstraction 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.
10
Each 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

11
Specifying an ADT
A rectangle example
  • ADT name

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.
12
Specifying 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.
13
Specifying 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.
14
Rectangle 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
15
Rectangle 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
16
UML Class Diagrams
Write a Comment
User Comments (0)
About PowerShow.com