Download presentation
Presentation is loading. Please wait.
1
Data Design and Implementation
Chapter 2 Data Design and Implementation
2
Data The representation of information in a manner suitable for communication or analysis by humans or machines. Data are the nouns of the programming world: The objects that are manipulated The information that is processed
3
Data Type Used to characterize and manipulate a certain variety of data. Formally defined by describing the collection of elements that it can represent (the domain) and the operations that may be performed on those elements.
4
Data Type Example Integer
5
Atomic Data Types Scalar data type A data type in which the values are ordered and each value is atomic Discrete (ordinal) data type A scalar data type in which each value (except the first) has a unique predecessor and each value (except the last) has a unique successor
6
Composite Data Types A data type whose elements are composed of multiple data items. For example, a calendar date is composed of a month value, a day value, and a year value UML Class Diagram showing composition
7
Data Abstraction Logical Properties Implementation
The separation of a data type’s logical properties from its implementation. Logical Properties Possible values Available operations Implementation A collection of bits interpreted in a particular manner
8
Data Encapsulation The hiding of the representation of data from the applications that use the data at a logical level; a programming language feature that enforces information hiding. Encapsulation of Ada’s Integer type
9
Abstract Data Type A data type whose properties (domain and operations) are specified independently of any particular implementation.
10
Data Structure A collection of data elements whose logical organization reflects a structural relationship among the elements. A data structure is characterized by accessing operations that are used to store and retrieve the individual data elements.
11
Features of Data Structures
They can be “decomposed” into their component elements. The organization of the elements is a feature of the structure that affects how each element is accessed. Both the arrangement of the elements and the way they are accessed can be encapsulated.
12
Relationships Between Data Type, Data Structure, and Abstract Data Type
An abstract data type encapsulates a data structure An abstract data type is a data type A data structure is composed of three features
13
Classification of Data Structure Operations
Constructor An operation used to create new values of a class Observer An operation that returns an observation on the state of an object. Transformer (mutator) An operation that changes the state of one or more of the data values Iterator An operation that allows us to process all the components in a data structure in some sequence.
14
Data From 3 Different Levels
Application (or user) level: modeling real-life data in a specific context. Logical (or ADT) level: abstract view of the domain and operations. Implementation level: specific representation of the structure to hold the data items, and the coding for operations. What How
15
Viewing A Library From 3 Different Levels
Application (or user) level: Library of Congress, or Baltimore County Public Library. Logical (or ADT) level: domain is a collection of books; operations include: check book out, check book in, pay fine, reserve a book. Implementation level: representation of the structure to hold the “books”, and the coding for operations.
16
Communication between the Application Level and Implementation Level
17
Ada’s Built-In Types
18
Scalar Types One research study on the nature of costly software faults indicates that poor models of scalar quantities were responsible for nearly 90% of the errors in the cases studied. “My Hairiest Bug War Stories,” M. Eisenstadt, Communications of the ACM, vol 40, no 4, 30-37, 1997. Forum Letter, J. McCormick, Communications of the ACM, vol 40, no 8, 30,1997.
19
Signed Integer Type Provides a range for modeling real-world whole signed numbers. type Car_Door_Type is range 2..6; Doors : Car_Door_Type;
20
Modular (Unsigned) Integer Type
Provides a range for modeling real-world whole unsigned numbers. Uses modular arithmetic. Can use logical operators type Clock is mod 12; -- Domain is 0 to 11 type Byte is mod 256; -- Domain is 0 to 255 Time : Clock; Register : Byte;
21
Enumeration Type Domain is an ordered set of identifiers
type Month_Type is (January, February, March, April, May, June, July, August, September, October, November, December); Month : Month_Type;
22
Real Types Not all real numbers can be stored exactly.
Those real numbers that can be stored exactly are called Model Numbers. There are very few model numbers. Any real number that is not a model number is stored as the closest model number.
23
Errors in Storing Real Numbers
The error in storing a real number may be expressed in two different ways. Absolute error The difference between the real number and the model number used to represent it. Relative error The absolute error divided by the true value of the real number.
24
Real Types in Ada Ada provides two types for storing real numbers.
Floating point types Fixed point types Choose the type based on the kind of error (absolute or relative) that is most relevant to your application.
25
Floating Point Types A floating point type uses a fixed number of digits (mantissa) and a base raised to a power (exponent) to approximate a real number. The base is usually 2, but we illustrate with a base of 10. x 10+34 Exponent Base Mantissa
26
Floating Point Types (cont.)
The following equivalent numbers illustrate the origin of the term floating point .0512 x x x x 106
27
Declaration of Floating Point Types
Two examples type Inches is digits 4 range ; type Feet is digits 6 range ; Digits specifies the minimum number of decimal digits in the numbers’ mantissa.
28
Fixed Point Types A fixed point number is stored as a single number with a fixed radix point. Ada provides two kinds of fixed point types Binary (ordinary) fixed point types Decimal fixed point types
29
Binary (Ordinary) Fixed Point Type Declarations
An ordinary fixed point number is stored as a single number with a fixed binary point. Two examples of binary fixed point types type Meters is delta range ; type Degrees is delta range ; Delta specifies the maximum distance between model numbers. The Ada compiler may use a smaller delta.
30
Decimal Fixed Point Type Declarations
A decimal fixed point number is stored as a single number with a fixed decimal point. Two examples of decimal fixed point types type Euro is delta 0.01 digits 8 range _000.0; type Peso is delta digits 9 range _000_000.0; Delta specifies the distance between model numbers. It must be a power of 10. Digits specifies the number of decimal digits in the number (to the left and right of the decimal point).
31
Floating Point Error The distance between model floating point numbers depends on the value of the exponent. The absolute error depends on the distance between model numbers. When the exponent is small, the distance between model numbers is small and when the exponent is large, the distance between model numbers is large. While absolute error changes with exponent, the relative error for a floating point number does not.
32
Fixed Point Error The distance between model floating point numbers is constant throughout the range. Therefore the absolute error is constant throughout the range. While absolute error is constant throughout the range, the relative error for a fixed point number increases as the number gets smaller.
33
Fixed or Floating Point?
Choose floating point when relative error is more important than absolute error for the real numbers in your application. Choose fixed point when absolute error is more important than relative error for the real numbers in your application.
34
Composite Types Ada provides two kinds of composite types
Array types (homogeneous components) Components are accessed by their position in the collection. Record types (heterogeneous components) Components are accessed by their name. Tagged records provide the mechanism for inheritance in Ada.
35
Packages Packages are Ada’s main mechanism for
Information Hiding Encapsulation Packages are written in two parts Package Specification Package Body What How
36
Kinds of Packages (a simple taxonomy)
Definition packages group together related constants and types. Service packages group together the constants, types, subtypes, and subprograms necessary to provide some particular service. Data Abstraction Packages are used to construct abstract data types (ADTs).
37
Private Types Are used to encapsulate the data of an abstract data type
38
Class A class is a specialized abstract data type (it has Inheritance)
In Ada, a class is implemented with a package (specification and body). In Ada, a class is declared in the package specification as a tagged, private type
39
Inheritance The tagged (record) type is the basis of inheritance in Ada. A tagged type may be extended with additional data fields. The primitive operations defined for a tagged type are inherited. Primitive operations may be overridden. Additional operations may be provided.
40
Primitive Operations Operations for a type that are declared in the same package specification as the type and has a parameter or a return value of the type. Only primitive operations for a class may be inherited by a subclass.
41
Operation Terminology
Parameter profile The distinguishing features of a subprogram—whether the subprogram is a procedure or function, the number of parameters, the type of each parameter, and , if it is a function, the type of the result. Sometimes called the subprogram's signature. Overloading The repeated use of a subprogram name with different parameter profiles. Overriding The replacement of a superclass's operation with one defined for the subclass.
42
UML Class Diagram Illustrating Inheritance
A tank car is a specialized railroad car. The tank car class overrides the railroad car’s Construct_Car and Put operations and uses the other three railroad car operations. The tank car class has three additional operations.
43
Singleton Classes A class for which there is only one object.
Also called an abstract data object (ADO). As with all classes in Ada, a singleton class is implemented with a package The package specification contains operations for the class but no tagged record that defines the class. The package body contains the declarations for the class and one variable holding the data for the one object.
44
Abstract Classes Instance An individual entity with its own identity. An object is an instance of a class. Abstract class A class that may have no direct instances. You cannot create an object of an abstract class. Concrete class A class that may have instances.
45
UML Class Hierarchy Rooted at an Abstract Class
Locomotive is an abstract class. This distinction is indicated by the use of italics. The other five subclasses are concrete classes.
46
Bingo Numbers Column Number Range B 1 to 15 I 16 to 30 N 31 to 45 G
47
Specification of Bingo Numbers
package Bingo_Numbers is - This package defines Bingo numbers and their associated letters - - The range of numbers on a Bingo Card type Bingo_Number is range 0..75; - - 0 can't be called, it is only for the Free Play square subtype Callable_Number is Bingo_Number range 1..75; - - Associations between Bingo numbers and letters subtype B_Range is Bingo_Number range ; subtype I_Range is Bingo_Number range ; subtype N_Range is Bingo_Number range ; subtype G_Range is Bingo_Number range ; subtype O_Range is Bingo_Number range ; - - The 5 Bingo letters type Bingo_Letter is (B, I, N, G, O); end Bingo_Numbers;
48
Initial Class Diagram for Bingo Simulation
49
Revised Class Diagram for Bingo Simulation
50
CRC Card for the Bingo Basket
51
CRC Card for a Bingo Card
52
CRC Card for a Bingo Caller
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.