Presentation is loading. Please wait.

Presentation is loading. Please wait.

Oriented Design and Abstract Data Type

Similar presentations


Presentation on theme: "Oriented Design and Abstract Data Type"— Presentation transcript:

1 Oriented Design and Abstract Data Type
CSCI 3333 Data Structures Oriented Design and Abstract Data Type

2 Acknowledgement Dr. Bun Yue Mr. Charles Moen

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

4 OOD Principles Abstraction Encapsulation Information hiding
Software Engineering (Goodrich, 59)‏ OOD Principles Abstraction Distill a complicated system into simple parts (objects) that can be easily described and understood e.g., a road map is an abstraction Encapsulation 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 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”

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

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

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

8 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;

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

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

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

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

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

14 Interface Specifies operations that are supported
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 Example: API = Application Programming Interface An ADT specifies an interface

15 Classes Software Engineering
In Java or C++, we implement an ADT by writing a class A class specifies allowed operations (methods) A class contains 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”

16 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 “set” methods “get” methods Advantage 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”

17 Questions and Comments?


Download ppt "Oriented Design and Abstract Data Type"

Similar presentations


Ads by Google