CSCI 3333 Data Structures Oriented Design and Abstract

CSCI 3333 Data Structures Oriented Design and Abstract Data Type

Acknowledgement Dr. Bun Yue ¡ Mr. Charles Moen ¡

Software Engineering (Goodrich, 58) OOD Goals ¡ Robustness l l ¡ Reusability l l l ¡ “Capable of handling unexpected inputs” Correct and safe Code should be reusable in other applications Class libraries like the Java Collections Framework General purpose code helps rapid development Adaptability l l l Able to evolve over time in response to changes Loosely connected classes Easy to maintain 3

Software Engineering (Goodrich, 59) OOD Principles ¡ Abstraction l l ¡ Encapsulation l l ¡ Distill a complicated system into simple parts (objects) that can be easily described and understood e. g. , a road map is an abstraction Data and the operations that can be performed with that data are kept in the same place – the objects Simplify a program by dividing it into distinct components or objects Information hiding l Internal details of a class are not revealed ¡ ¡ We don’t need to know how it’s done We just need to know the “interface” 4

Software Engineering Data Type Defined by: A range of data values The operations that can be performed on the data Example: int data type l l Type of data: integer values from -231 to 231 - 1 Operations supported: arithmetic (+, –, *, /, %), assignment (=), equality (==, !=), relational (<, >, <=, >=), increment (++), decrement (––), etc. 5

Strongly-Typed Languages ¡ Strongly typed languages: more restrictive values, operations and type conversions. l l l More compilation time checking More reliable More restrictive.

Data Value Examples: Ada’s subtypes: subtype Day is Integer range 1. . 31; subtype Upper_Chars is Character range 'A'. . 'Z'; Perl: $i = 1; $i = “This is cool”;

Type Checking Strong type checking increases programming reliability. Example: consider the generic code for two int: if (p >= q) s = p; else s = q; t = p + q – s; ¡

Problem with the Example Code Is it equivalent to t = min(p, q)? ¡ Poorly written. ¡ May have different results depending on languages. ¡

Operation Examples Java’s and C++ classes: only methods defined in the class and super class or base class are available.

Type Conversion Examples C++: int i = 10; unsigned int j = 20; i = j; // implicit type conversion ¡ Implicit type conversion is a frequent source of program errors.

Abstract Data Type ¡ A specification for a data structure that tells us l l ¡ The type of data stored The operations that are supported Specifies what the operations do, but not how they do it (Goodrich, p. 60)

Why ADT? Unexpected data values should be handled. ¡ Unexpected operations create problems. ¡

Software Engineering Interface ¡ Specifies operations that are supported ¡ Specifies what the operations do, but not how they do it ¡ We depend on the interface to tell us how to use a programming feature l ¡ Example: API = Application Programming Interface An ADT specifies an interface 14

Software Engineering Classes ¡ In Java or C++, we implement an ADT by writing a class l ¡ A class specifies allowed operations (methods) A class contains l l l Data ¡ Called “instance variables” ¡ Usually private Operations ¡ Operations that can be performed on the data ¡ Called “methods” ¡ Usually public The public operations are considered the “interface” 15

Software Engineering Information Hiding ¡ Accomplished by keeping the instance variables private ¡ The user of an object in your program can change its data, but cannot change it directly ¡ Data members are manipulated only by accessor methods l l ¡ “set” methods “get” methods Advantage l l l We can control how the data is changed We can control how the data is stored Other parts of the program don’t need to know how it’s done, they just need to know the “interface” 16

Questions and Comments?
- Slides: 17