Data Design and Implementation

Slides:



Advertisements
Similar presentations
Programming Languages and Paradigms
Advertisements

1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 2: Data types and addressing modes dr.ir. A.C. Verschueren.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
ITEC200 – Week03 Inheritance and Class Hierarchies.
2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.
UML – Class Diagrams.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Introduction.
High-Level Programming Languages
Chapter 2 Data Design and Implementation. Homework You should have already read section 2.2 You should have already read section 2.2 Read Section 2.3.
Introduction to Computers and Programming. Some definitions Algorithm: –A procedure for solving a problem –A sequence of discrete steps that defines such.
7M701 1 Class Diagram advanced concepts. 7M701 2 Characteristics of Object Oriented Design (OOD) objectData and operations (functions) are combined 
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Introduction.
Chapter 8 High-Level Programming Languages Nell Dale John Lewis.
Structured Data Types and Encapsulation Mechanisms to create new data types: –Structured data Homogeneous: arrays, lists, sets, Non-homogeneous: records.
Introduction to Computers and Programming. Some definitions Algorithm: Algorithm: A procedure for solving a problem A procedure for solving a problem.
Abstract Data Types and Encapsulation Concepts
UML Class Diagrams: Basic Concepts. Objects –The purpose of class modeling is to describe objects. –An object is a concept, abstraction or thing that.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Object-Oriented Modeling Chapter 10 CSCI CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.
Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.
1 2 Data Design and Implementation Chapter 2 Data Design and Implementation.
ISBN Chapter 6 Data Types Introduction Primitive Data Types User-Defined Ordinal Types.
Object-Oriented Programming •Object-Oriented Programming (OOP) allows you to create your program based upon modeling objects.  Your program’s properties.
Views of Data Data – nouns of programming world the objects that are manipulated information that is processed Humans like to group information Classes,
Object-Oriented Programming © 2013 Goodrich, Tamassia, Goldwasser1Object-Oriented Programming.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 11 Object-Oriented.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Object-Oriented Design.
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
1 Chapter 11 © 1998 by Addison Wesley Longman, Inc The Concept of Abstraction - The concept of abstraction is fundamental in programming - Nearly.
1 CS Programming Languages Class 22 November 14, 2000.
Chapter 1 Data Abstraction: The Walls CS Data Structures Mehmet H Gunes Modified from authors’ slides.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Lecture 2: Review of Object Orientation. © Lethbridge/La ganière 2005 Chapter 2: Review of Object Orientation What is Object Orientation? Procedural.
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
CSCE 240 – Intro to Software Engineering Lecture 3.
Chapter 11: Abstract Data Types Lecture # 17. Chapter 11 Topics The Concept of Abstraction Advantages of Abstract Data Types Design Issues for Abstract.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Logical Database Design and the Rational Model
Chapter 3 Sets.
Abstract Data Types and Encapsulation Concepts
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
Chapter 11 Object-Oriented Design
CS 326 Programming Languages, Concepts and Implementation
11.1 The Concept of Abstraction
About the Presentations
Data Structures Mohammed Thajeel To the second year students
Abstract Data Types and Encapsulation Concepts
UML Class Diagrams: Basic Concepts
Object Based Programming
Object Oriented Analysis and Design
Object-Oriented Programming
Seminar 3 UML Class Diagram.
Introduction to Abstract Data Types
Abstract Data Types and Encapsulation Concepts
Lecture 22 Inheritance Richard Gesick.
Slides by Steve Armstrong LeTourneau University Longview, TX
ISC321 Database Systems I Chapter 10: Object and Object-Relational Databases: Concepts, Models, Languages, and Standards Spring 2015 Dr. Abdullah Almutairi.
Chapter 20 Object-Oriented Analysis and Design
Chapter 12 Abstract Classes and Interfaces
Copyright 2007 Oxford Consulting, Ltd
Introduction to Data Structure
Intro to Data Structures and ADTs
CS 112 Programming 2 Lecture 02 Abstract Classes & Interfaces (2)
Chapter 22 Object-Oriented Systems Analysis and Design and UML
C Language B. DHIVYA 17PCA140 II MCA.
11.1 The Concept of Abstraction
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Presentation transcript:

Data Design and Implementation Chapter 2 Data Design and Implementation

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

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.

Data Type Example Integer

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

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

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

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

Abstract Data Type A data type whose properties (domain and operations) are specified independently of any particular implementation.

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.

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.

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

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.

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

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.

Communication between the Application Level and Implementation Level

Ada’s Built-In Types

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.

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;

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;

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;

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.

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.

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.

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. .71358 x 10+34 Exponent Base Mantissa

Floating Point Types (cont.) The following equivalent numbers illustrate the origin of the term floating point .0512 x 109 .512 x 108 5.12 x 107 51.2 x 106

Declaration of Floating Point Types Two examples type Inches is digits 4 range 0.00..100.00; type Feet is digits 6 range 0.00..1000.00; Digits specifies the minimum number of decimal digits in the numbers’ mantissa.

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

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 0.001 range -1000.0..1000.0; type Degrees is delta 0.25 range 0.0..100.0; Delta specifies the maximum distance between model numbers. The Ada compiler may use a smaller delta.

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 0.0 .. 100_000.0; type Peso is delta 0.1 digits 9 range 0.0 ..10_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).

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.

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.

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.

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.

Packages Packages are Ada’s main mechanism for Information Hiding Encapsulation Packages are written in two parts Package Specification Package Body What How

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).

Private Types Are used to encapsulate the data of an abstract data type

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

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.

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.

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.

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.

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.

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.

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.

Bingo Numbers Column Number Range B 1 to 15 I 16 to 30 N 31 to 45 G

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 1..15; subtype I_Range is Bingo_Number range 16..30; subtype N_Range is Bingo_Number range 31..45; subtype G_Range is Bingo_Number range 46..60; subtype O_Range is Bingo_Number range 61..75; - - The 5 Bingo letters type Bingo_Letter is (B, I, N, G, O); end Bingo_Numbers;

Initial Class Diagram for Bingo Simulation

Revised Class Diagram for Bingo Simulation

CRC Card for the Bingo Basket

CRC Card for a Bingo Card

CRC Card for a Bingo Caller