Home | | Object Oriented Programming | Data Abstraction - C++

Chapter: Object Oriented Programming(OOP) : Basic Characteristics of OOP

Data Abstraction - C++

Abstract Data Types • Introduction to...Object Models • Introduction to...Data Abstraction • Using Data Abstraction in C++ ...an introduction to the class

DATA ABSTRACTION

 

         Abstract Data Types

         Introduction to...Object Models

         Introduction to...Data Abstraction

         Using Data Abstraction in C++ ...an introduction to the class

         Members of a Class

         The class interface, using the class, the class interface versus implementation

         Classes versus Structures

         Constructors, Destructors

 

         Dynamic Memory and Linked Lists

 

         The most important aspect of C++ is its ability to support many different programming paradigms

 

         procedural abstraction

         modular abstraction

         data abstraction

 

         object oriented programming (this is discussed later, once we learn about the concept of inheritance)

 

1. Procedural Abstraction

 

         This is where you build a “fence” around program segments, preventing some parts of the program from “seeing” how tasks are being accomplished.

 

 

         Any use of globals causes side effects that may not be predictable, reducing the viability of procedural abstraction

 

2. Modular Abstraction

 

         With modular abstraction, we build a “screen” surrounding the internal structure of our program prohibiting programmers from accessing the data except through specified functions.

 

         Many times data structures (e.g., structures) common to a module are placed in a header files along with prototypes (allows external references)

 

3. Data Abstraction

         Data Abstraction is one of the most powerful programming paradigms

         It allows us to create our own user defined data types (using the class construct) and

         then define variables (i.e., objects) of those new data types.

 

         With data abstraction we think about what operations can be performed on a particular type of data and not how it does it

 

         Here we are one step closer to object oriented programming

         Data abstraction is used as a tool to increase the modularity of a program

         It is used to build walls between a program and its data structures

         what is a data structure?

         talk about some examples of data structures

         We use it to build new abstract data types

         An abstract data type (ADT) is a data type that we create

         consists of data and operations that can be performed on that data

         Think about a char type

 

         it consists of 1 byte of memory and operations such as assignment, input, output, arithmetic operations can be performed on the data

 

         An abstract data type is any type you want to add to the language over and above the

fundamental types

•   For example, you might want to add a new type called:         list

         which maintains a list of data

         the data structure might be an array of structures

         operations might be to add to, remove, display all, display some items in the list

         Once defined, we can create lists without worrying about how the data is stored

 

         We “hide” the data structure used for the data within the data type -- so it is transparent to the program using the data type

 

         We call the program using this new data type: the client program (or client)

 

         Once we have defined what data and operations make sense for a new data type, we can define them using the class construct in C++

 

         Once you have defined a class, you can create as many instances of that class as you want

         Each “instance” of the class is considered to be an “object” (variable)

         Think of a class as similar to a data type

         and an object as a variable

         And, just as we can have zero or more variables of any data type...

         we can have zero or more objects of a class!

 

         Then, we can perform operations on an object in the same way that we can access members of a struct...

 

 

 

         An abstraction is a view or representation of an entity that includes only the most significant attributes

 

         The concept of abstraction is fundamental in programming (and computer science)

         Nearly all programming languages support process abstraction with subprograms

         Nearly all programming languages designed since 1980 support data abstraction

 

         An abstract data type is a user-defined data type that satisfies the following two conditions:

 

         The representation of, and operations on, objects of the type are defined in a single syntactic unit

 

         The representation of objects of the type is hidden from the program units that use these objects, so the only operations possible are those provided in the type's definition

 

Advantages of Data Abstraction

 

         Advantage of the first condition

 

– Program organization, modifiability (everything associated with a data structure is together), and separate compilation

 

         Advantage the second condition

 

– Reliability--by hiding the data representations, user code cannot directly access objects of the type or depend on the representation, allowing the representation to be changed without affecting user code

 

EXAMPLE

class Stack {

 

private:

int *stackPtr, maxLen, topPtr;

public:

 

Stack() { // a constructor stackPtr = new int [100]; maxLen = 99;

 

topPtr = -1;

};

 

~Stack () {delete [] stackPtr;};

void push (int num) {…}; void pop () {…};

 

int top () {…}; int empty () {…};

 

} // Stack.h - the header file for the Stack class #include <iostream.h>

 

class Stack {

 

private: //** These members are visible only to other //** members and friends (see Section 11.6.4)

 

int *stackPtr; int maxLen; int topPtr;

 

public: //** These members are visible to clients

 


Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Object Oriented Programming(OOP) : Basic Characteristics of OOP : Data Abstraction - C++ |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.