SlideShare una empresa de Scribd logo
1 de 44
© 2005 Pearson Addison-Wesley. All rights reserved 3-1
Abstract Data Types
• Modularity
– Keeps the complexity of a large program
manageable by systematically controlling
the interaction of its components
– Isolates errors
© 2005 Pearson Addison-Wesley. All rights reserved 3-2
Abstract Data Types
• Modularity (Continued)
– Eliminates redundancies
– A modular program is
• Easier to write
• Easier to read
• Easier to modify
© 2005 Pearson Addison-Wesley. All rights reserved 3-3
Abstract Data Types
• Procedural abstraction
– Separates the purpose and use of a module from
its implementation
– A module’s specifications should
• Detail how the module behaves
• Identify details that can be hidden within the module
© 2005 Pearson Addison-Wesley. All rights reserved 3-4
Abstract Data Types
• Information hiding
– Hides certain implementation details within a
module
– Makes these details inaccessible from outside
the module
© 2005 Pearson Addison-Wesley. All rights reserved 3-5
Abstract Data Types
Figure 3.1
Isolated tasks: the implementation of task T does not affect task Q
© 2005 Pearson Addison-Wesley. All rights reserved 3-6
Abstract Data Types
• The isolation of modules is not total
– Functions’ specifications, or contracts, govern how they interact with each
other
Figure 3.2 A slit in the wall
© 2005 Pearson Addison-Wesley. All rights reserved 3-7
Abstract Data Types
• Typical operations on data
– Add data to a data collection
– Remove data from a data collection
– Ask questions about the data in a data
collection
© 2005 Pearson Addison-Wesley. All rights reserved 3-8
Abstract Data Types
• Data abstraction
– Asks you to think what you can do to a
collection of data independently of how you do
it
– Allows you to develop each data structure in
relative isolation from the rest of the solution
– A natural extension of procedural abstraction
© 2005 Pearson Addison-Wesley. All rights reserved 3-9
Abstract Data Types
• Abstract data type (ADT)
– An ADT is composed of
• A collection of data
• A set of operations on that data
– Specifications of an ADT indicate
• What the ADT operations do, not how to implement
them
– Implementation of an ADT
• Includes choosing a particular data structure
© 2005 Pearson Addison-Wesley. All rights reserved 3-10
Abstract Data Types
Figure 3.4
A wall of ADT operations isolates a data structure from the program that uses it
© 2005 Pearson Addison-Wesley. All rights reserved 3-11
The ADT List
• Except for the first and last items, each item
has a unique predecessor and a unique
successor
• Head or front do not have a predecessor
• Tail or end do not have a successor
© 2005 Pearson Addison-Wesley. All rights reserved 3-12
The ADT List
• Items are referenced by their position within
the list
• Specifications of the ADT operations
– Define the contract for the ADT list
– Do not specify how to store the list or how to
perform the operations
• ADT operations can be used in an
application without the knowledge of how
the operations will be implemented
© 2005 Pearson Addison-Wesley. All rights reserved 3-13
The ADT List
• ADT List operations
– Create an empty list
– Determine whether a list is empty
– Determine the number of items in a list
– Add an item at a given position in the list
– Remove the item at a given position in the list
– Remove all the items from the list
– Retrieve (get) item at a given position in the list
© 2005 Pearson Addison-Wesley. All rights reserved 3-14
The ADT List
• The ADT sorted list
– Maintains items in sorted order
– Inserts and deletes items by their values, not
their positions
© 2005 Pearson Addison-Wesley. All rights reserved 3-15
The ADT List
Figure 3.7
The wall between displayList and the implementation of the ADT list
© 2005 Pearson Addison-Wesley. All rights reserved 3-16
Designing an ADT
• The design of an ADT should evolve
naturally during the problem-solving
process
• Questions to ask when designing an ADT
– What data does a problem require?
– What operations does a problem require?
© 2005 Pearson Addison-Wesley. All rights reserved 3-17
Designing an ADT
• For complex abstract data types, the
behavior of the operations must be specified
using axioms
– Axiom: A mathematical rule
– Ex. : (aList.createList()).size() = 0
© 2005 Pearson Addison-Wesley. All rights reserved 3-18
Implementing ADTs
• Choosing the data structure to represent the
ADT’s data is a part of implementation
– Choice of a data structure depends on
• Details of the ADT’s operations
• Context in which the operations will be used
© 2005 Pearson Addison-Wesley. All rights reserved 3-19
Implementing ADTs
• Implementation details should be hidden
behind a wall of ADT operations
– A program would only be able to access the
data structure using the ADT operations
© 2005 Pearson Addison-Wesley. All rights reserved 3-20
Implementing ADTs
Figure 3.8
ADT operations provide access to a data structure
© 2005 Pearson Addison-Wesley. All rights reserved 3-21
Implementing ADTs
Figure 3.9 Violating the wall of ADT operations
© 2005 Pearson Addison-Wesley. All rights reserved 3-22
C++ Classes
• Encapsulation combines an ADT’s data
with its operations to form an object
– An object is an instance of a class
– A class contains data members and member
functions
• By default, all members in a class are
private
© 2005 Pearson Addison-Wesley. All rights reserved 3-23
C++ Classes
• Each class definition is placed in a header
file
– Classname.h
• The implementation of a class’s member
functions are placed in an implementation
file
– Classname.cpp
© 2005 Pearson Addison-Wesley. All rights reserved 3-24
C++ Classes
Figure 3.10
An object’s data and methods
are encapsulated
© 2005 Pearson Addison-Wesley. All rights reserved 3-25
Class Constructors and
Destructors
• Constructors
– Create and initialize new instances of a class
– Have the same name as the class
– Have no return type, not even void
© 2005 Pearson Addison-Wesley. All rights reserved 3-26
Class Constructors and
Destructors
• A class can have several constructors
– A default constructor has no arguments
– Initializers can set data members to initial
values
– The compiler will generate a default constructor
if one is omitted
© 2005 Pearson Addison-Wesley. All rights reserved 3-27
Class Constructors and
Destructors
• The implementation of a constructor (or any
member function) is qualified with the
scope resolution operator ::
Sphere::Sphere(double
initialRadius) :
theRadius(initialRadius)
© 2005 Pearson Addison-Wesley. All rights reserved 3-28
Class Constructors and
Destructors
• Destructors
– Destroy an instance of an object when the
object’s lifetime ends
• Each class has one destructor
– For many classes, the destructor can be omitted
– The compiler will generate a default constructor
if one is omitted
© 2005 Pearson Addison-Wesley. All rights reserved 3-29
Inheritance in C++
• A derived class or subclass inherits any of
the publicly defined functions or data
members of a base class or superclass
© 2005 Pearson Addison-Wesley. All rights reserved 3-30
Inheritance in C++
• An instance of a derived class can invoke
public methods of the base class:
#include “Sphere.h”
enum Color {RED, BLUE, GREEN, YELLOW}
class ColoredSphere: public Sphere
{
public:
…
Color getColor() const;
…
© 2005 Pearson Addison-Wesley. All rights reserved 3-31
C++ Namespaces
• A mechanism for logically grouping
declarations and definitions into a common
declarative region
© 2005 Pearson Addison-Wesley. All rights reserved 3-32
C++ Namespaces
• The contents of the namespace can be
accessed by code inside or outside the
namespace
– Use the scope resolution operator to access
elements from outside the namespace
– Alternatively, the using declaration allows
the names of the elements to be used directly
© 2005 Pearson Addison-Wesley. All rights reserved 3-33
C++ Namespaces
• Creating a namespace
namespace smallNamespace
{
int count = 0;
void abc();
} //end smallNamespace
• Using a namespace
using namespace smallNamespace;
count +=1;
abc();
© 2005 Pearson Addison-Wesley. All rights reserved 3-34
C++ Namespaces
• Items declared in the C++ Standard Library
are declared in the std namespace
• C++ include files for several functions are
in the std namespace
– To include input and output functions from the
C++ library, write
include <iostream>
using namespace std;
© 2005 Pearson Addison-Wesley. All rights reserved 3-35
An Array-Based ADT List
• A list’s items are stored in an array items
• Both an array and a list identify their items
by number
© 2005 Pearson Addison-Wesley. All rights reserved 3-36
An Array-Based ADT List
• A list’s kth
item will be stored in items[k-
1]
Figure 3.11 An array-based implementation of the ADT list
© 2005 Pearson Addison-Wesley. All rights reserved 3-37
C++ Exceptions
• Exception
– A mechanism for handling an error during
execution
– A function indicates that an error has occurred
by throwing an exception
– The code that deals with the exception is said to
catch or handle it
© 2005 Pearson Addison-Wesley. All rights reserved 3-38
C++ Exceptions
• Throwing exceptions
– A throw statement is used to throw an
exception
throw ExceptionClass (stringArgument);
© 2005 Pearson Addison-Wesley. All rights reserved 3-39
C++ Exceptions
• try block
– A statement that might throw an exception is
placed within a try block
– Syntax
try {
statement(s);
} // end try
© 2005 Pearson Addison-Wesley. All rights reserved 3-40
C++ Exceptions
• catch block
– Used to catch an exception and deal with the
error condition
– Syntax
catch (exceptionClass identifier) {
statement(s);
} // end catch
© 2005 Pearson Addison-Wesley. All rights reserved 3-41
C++ Exceptions
• A programmer-define ListException class
#include <exception>
#include <string>
using namespace std;
class ListException: public exception
{
public:
ListException (const string & message =
“”)
: exception(message.c_str())
{}
}; // end ListException
© 2005 Pearson Addison-Wesley. All rights reserved 3-42
Summary
• Data abstraction controls the interaction
between a program and its data structures
• Abstract data type (ADT): a set of data-
management operations together with the
data values upon which they operate
• Mathematical study of ADTs uses axioms to
specify the behavior of ADT operations
• An ADT should be fully defined before any
implementation decisions
© 2005 Pearson Addison-Wesley. All rights reserved 3-43
Summary
• Hide an ADT’s implementation by defining
the ADT as a C++ class
• An object encapsulates both data and
operations
• A class contains at least one constructor and
a destructor
• The compiler generates default constructor
and destructor if none are provided
© 2005 Pearson Addison-Wesley. All rights reserved 3-44
Summary
• Members of a class are private by default
– Data members are typically private
– Public functions can be provided to access them
• Define and implement a class within header
and implementation files
• Namespace: a mechanism to group classes,
functions, variables, types, and constants
• Use exception handling to throw, catch, and
handle errors during program execution

Más contenido relacionado

La actualidad más candente

Elementary data structure
Elementary data structureElementary data structure
Elementary data structureBiswajit Mandal
 
Lecture 01 Intro to DSA
Lecture 01 Intro to DSALecture 01 Intro to DSA
Lecture 01 Intro to DSANurjahan Nipa
 
Data structures Basics
Data structures BasicsData structures Basics
Data structures BasicsDurgaDeviCbit
 
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyDatastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyMalikireddy Bramhananda Reddy
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)Elavarasi K
 
Data structures (introduction)
 Data structures (introduction) Data structures (introduction)
Data structures (introduction)Arvind Devaraj
 
Data structure lecture 2
Data structure lecture 2Data structure lecture 2
Data structure lecture 2Abbott
 
Abstract data types
Abstract data typesAbstract data types
Abstract data typesHoang Nguyen
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its typesNavtar Sidhu Brar
 
Data Structure and Algorithms
Data Structure and AlgorithmsData Structure and Algorithms
Data Structure and Algorithmsiqbalphy1
 
Introduction to Data Structure
Introduction to Data Structure Introduction to Data Structure
Introduction to Data Structure Prof Ansari
 
Data structure power point presentation
Data structure power point presentation Data structure power point presentation
Data structure power point presentation Anil Kumar Prajapati
 
Lecture 07 Data Structures - Basic Sorting
Lecture 07 Data Structures - Basic SortingLecture 07 Data Structures - Basic Sorting
Lecture 07 Data Structures - Basic SortingHaitham El-Ghareeb
 
DATA STRUCTURE IN C LANGUAGE
DATA STRUCTURE IN C LANGUAGEDATA STRUCTURE IN C LANGUAGE
DATA STRUCTURE IN C LANGUAGEshubhamrohiwal6
 
Data Structure
Data StructureData Structure
Data Structuresheraz1
 

La actualidad más candente (20)

M v bramhananda reddy dsa complete notes
M v bramhananda reddy dsa complete notesM v bramhananda reddy dsa complete notes
M v bramhananda reddy dsa complete notes
 
Elementary data structure
Elementary data structureElementary data structure
Elementary data structure
 
Data structures
Data structuresData structures
Data structures
 
Lecture 01 Intro to DSA
Lecture 01 Intro to DSALecture 01 Intro to DSA
Lecture 01 Intro to DSA
 
Data structures Basics
Data structures BasicsData structures Basics
Data structures Basics
 
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyDatastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)
 
Data structures (introduction)
 Data structures (introduction) Data structures (introduction)
Data structures (introduction)
 
Data structure lecture 2
Data structure lecture 2Data structure lecture 2
Data structure lecture 2
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Data Structures
Data StructuresData Structures
Data Structures
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its types
 
Data Structure and Algorithms
Data Structure and AlgorithmsData Structure and Algorithms
Data Structure and Algorithms
 
Ds chapter 2
Ds chapter 2Ds chapter 2
Ds chapter 2
 
Introduction to Data Structure
Introduction to Data Structure Introduction to Data Structure
Introduction to Data Structure
 
Data structure power point presentation
Data structure power point presentation Data structure power point presentation
Data structure power point presentation
 
Lecture 07 Data Structures - Basic Sorting
Lecture 07 Data Structures - Basic SortingLecture 07 Data Structures - Basic Sorting
Lecture 07 Data Structures - Basic Sorting
 
DATA STRUCTURE IN C LANGUAGE
DATA STRUCTURE IN C LANGUAGEDATA STRUCTURE IN C LANGUAGE
DATA STRUCTURE IN C LANGUAGE
 
Lecture-05-DSA
Lecture-05-DSALecture-05-DSA
Lecture-05-DSA
 
Data Structure
Data StructureData Structure
Data Structure
 

Destacado

03 data abstraction
03 data abstraction03 data abstraction
03 data abstractionOpas Kaewtai
 
Slide 3 data abstraction & 3 schema
Slide 3 data abstraction & 3 schemaSlide 3 data abstraction & 3 schema
Slide 3 data abstraction & 3 schemaVisakh V
 
Introduction to Data Abstraction
Introduction to Data AbstractionIntroduction to Data Abstraction
Introduction to Data AbstractionDennis Gajo
 
2CPP14 - Abstraction
2CPP14 - Abstraction2CPP14 - Abstraction
2CPP14 - AbstractionMichael Heron
 
บทที่ 2 สถาปัตยกรรม
บทที่ 2 สถาปัตยกรรมบทที่ 2 สถาปัตยกรรม
บทที่ 2 สถาปัตยกรรมPrinceStorm Nueng
 
Preparation Data Structures 03 abstract data_types
Preparation Data Structures 03 abstract data_typesPreparation Data Structures 03 abstract data_types
Preparation Data Structures 03 abstract data_typesAndres Mendez-Vazquez
 
Degrees of data abstraction
Degrees of data abstractionDegrees of data abstraction
Degrees of data abstractionMary May Porto
 
Modular Architectures: What they are why do they matter now.
Modular Architectures: What they are why do they matter now.Modular Architectures: What they are why do they matter now.
Modular Architectures: What they are why do they matter now.Param Rengaiah
 
Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++Liju Thomas
 
11 abstract data types
11 abstract data types11 abstract data types
11 abstract data typesjigeno
 

Destacado (15)

03 data abstraction
03 data abstraction03 data abstraction
03 data abstraction
 
Abstract Data Types
Abstract Data TypesAbstract Data Types
Abstract Data Types
 
Slide 3 data abstraction & 3 schema
Slide 3 data abstraction & 3 schemaSlide 3 data abstraction & 3 schema
Slide 3 data abstraction & 3 schema
 
Introduction to Data Abstraction
Introduction to Data AbstractionIntroduction to Data Abstraction
Introduction to Data Abstraction
 
2CPP14 - Abstraction
2CPP14 - Abstraction2CPP14 - Abstraction
2CPP14 - Abstraction
 
บทที่ 2 สถาปัตยกรรม
บทที่ 2 สถาปัตยกรรมบทที่ 2 สถาปัตยกรรม
บทที่ 2 สถาปัตยกรรม
 
Preparation Data Structures 03 abstract data_types
Preparation Data Structures 03 abstract data_typesPreparation Data Structures 03 abstract data_types
Preparation Data Structures 03 abstract data_types
 
Degrees of data abstraction
Degrees of data abstractionDegrees of data abstraction
Degrees of data abstraction
 
Modular Architectures: What they are why do they matter now.
Modular Architectures: What they are why do they matter now.Modular Architectures: What they are why do they matter now.
Modular Architectures: What they are why do they matter now.
 
New coke
New cokeNew coke
New coke
 
Fddi
FddiFddi
Fddi
 
Product Architecture
Product ArchitectureProduct Architecture
Product Architecture
 
Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++
 
11 abstract data types
11 abstract data types11 abstract data types
11 abstract data types
 
Data dictionary
Data dictionaryData dictionary
Data dictionary
 

Similar a Data abstraction the walls

Topic12ADTS_GenericDataStructures.ppt
Topic12ADTS_GenericDataStructures.pptTopic12ADTS_GenericDataStructures.ppt
Topic12ADTS_GenericDataStructures.pptBlackSeraph
 
Topic12ADTS_GenericDataStructures.ppt
Topic12ADTS_GenericDataStructures.pptTopic12ADTS_GenericDataStructures.ppt
Topic12ADTS_GenericDataStructures.pptMeenakshiPatel13
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_II_08-08-2022_D...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_II_08-08-2022_D...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_II_08-08-2022_D...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_II_08-08-2022_D...AntareepMajumder
 
II B.Sc IT DATA STRUCTURES.pptx
II B.Sc IT DATA STRUCTURES.pptxII B.Sc IT DATA STRUCTURES.pptx
II B.Sc IT DATA STRUCTURES.pptxsabithabanu83
 
data structure
data structuredata structure
data structurehashim102
 
Abstract data types
Abstract data typesAbstract data types
Abstract data typesHarry Potter
 
Abstract data types
Abstract data typesAbstract data types
Abstract data typesTony Nguyen
 
Abstract data types
Abstract data typesAbstract data types
Abstract data typesFraboni Ec
 
Abstract data types
Abstract data typesAbstract data types
Abstract data typesJames Wong
 
Abstract data types
Abstract data typesAbstract data types
Abstract data typesYoung Alista
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdNimmi Weeraddana
 
Session 15 - Collections - Array List
Session 15 - Collections - Array ListSession 15 - Collections - Array List
Session 15 - Collections - Array ListPawanMM
 

Similar a Data abstraction the walls (20)

Topic12ADTS_GenericDataStructures.ppt
Topic12ADTS_GenericDataStructures.pptTopic12ADTS_GenericDataStructures.ppt
Topic12ADTS_GenericDataStructures.ppt
 
Topic12ADTS_GenericDataStructures.ppt
Topic12ADTS_GenericDataStructures.pptTopic12ADTS_GenericDataStructures.ppt
Topic12ADTS_GenericDataStructures.ppt
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_II_08-08-2022_D...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_II_08-08-2022_D...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_II_08-08-2022_D...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_II_08-08-2022_D...
 
II B.Sc IT DATA STRUCTURES.pptx
II B.Sc IT DATA STRUCTURES.pptxII B.Sc IT DATA STRUCTURES.pptx
II B.Sc IT DATA STRUCTURES.pptx
 
4-OOPS.pptx
4-OOPS.pptx4-OOPS.pptx
4-OOPS.pptx
 
data structure
data structuredata structure
data structure
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
U nit i data structure-converted
U nit   i data structure-convertedU nit   i data structure-converted
U nit i data structure-converted
 
ch11-1.ppt
ch11-1.pptch11-1.ppt
ch11-1.ppt
 
dsa.ppt
dsa.pptdsa.ppt
dsa.ppt
 
dsa.ppt
dsa.pptdsa.ppt
dsa.ppt
 
dsa (1).ppt
dsa (1).pptdsa (1).ppt
dsa (1).ppt
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pd
 
Lec3
Lec3Lec3
Lec3
 
Session 15 - Collections - Array List
Session 15 - Collections - Array ListSession 15 - Collections - Array List
Session 15 - Collections - Array List
 

Más de Hoang Nguyen

Rest api to integrate with your site
Rest api to integrate with your siteRest api to integrate with your site
Rest api to integrate with your siteHoang Nguyen
 
How to build a rest api
How to build a rest apiHow to build a rest api
How to build a rest apiHoang Nguyen
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsHoang Nguyen
 
How analysis services caching works
How analysis services caching worksHow analysis services caching works
How analysis services caching worksHoang Nguyen
 
Hardware managed cache
Hardware managed cacheHardware managed cache
Hardware managed cacheHoang Nguyen
 
Directory based cache coherence
Directory based cache coherenceDirectory based cache coherence
Directory based cache coherenceHoang Nguyen
 
Python your new best friend
Python your new best friendPython your new best friend
Python your new best friendHoang Nguyen
 
Python language data types
Python language data typesPython language data types
Python language data typesHoang Nguyen
 
Programming for engineers in python
Programming for engineers in pythonProgramming for engineers in python
Programming for engineers in pythonHoang Nguyen
 
Extending burp with python
Extending burp with pythonExtending burp with python
Extending burp with pythonHoang Nguyen
 
Cobol, lisp, and python
Cobol, lisp, and pythonCobol, lisp, and python
Cobol, lisp, and pythonHoang Nguyen
 
Object oriented programming using c++
Object oriented programming using c++Object oriented programming using c++
Object oriented programming using c++Hoang Nguyen
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysisHoang Nguyen
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithmsHoang Nguyen
 

Más de Hoang Nguyen (20)

Rest api to integrate with your site
Rest api to integrate with your siteRest api to integrate with your site
Rest api to integrate with your site
 
How to build a rest api
How to build a rest apiHow to build a rest api
How to build a rest api
 
Api crash
Api crashApi crash
Api crash
 
Smm and caching
Smm and cachingSmm and caching
Smm and caching
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessors
 
How analysis services caching works
How analysis services caching worksHow analysis services caching works
How analysis services caching works
 
Hardware managed cache
Hardware managed cacheHardware managed cache
Hardware managed cache
 
Directory based cache coherence
Directory based cache coherenceDirectory based cache coherence
Directory based cache coherence
 
Cache recap
Cache recapCache recap
Cache recap
 
Python your new best friend
Python your new best friendPython your new best friend
Python your new best friend
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python basics
Python basicsPython basics
Python basics
 
Programming for engineers in python
Programming for engineers in pythonProgramming for engineers in python
Programming for engineers in python
 
Learning python
Learning pythonLearning python
Learning python
 
Extending burp with python
Extending burp with pythonExtending burp with python
Extending burp with python
 
Cobol, lisp, and python
Cobol, lisp, and pythonCobol, lisp, and python
Cobol, lisp, and python
 
Object oriented programming using c++
Object oriented programming using c++Object oriented programming using c++
Object oriented programming using c++
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
 
Object model
Object modelObject model
Object model
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 

Último

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 

Último (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

Data abstraction the walls

  • 1. © 2005 Pearson Addison-Wesley. All rights reserved 3-1 Abstract Data Types • Modularity – Keeps the complexity of a large program manageable by systematically controlling the interaction of its components – Isolates errors
  • 2. © 2005 Pearson Addison-Wesley. All rights reserved 3-2 Abstract Data Types • Modularity (Continued) – Eliminates redundancies – A modular program is • Easier to write • Easier to read • Easier to modify
  • 3. © 2005 Pearson Addison-Wesley. All rights reserved 3-3 Abstract Data Types • Procedural abstraction – Separates the purpose and use of a module from its implementation – A module’s specifications should • Detail how the module behaves • Identify details that can be hidden within the module
  • 4. © 2005 Pearson Addison-Wesley. All rights reserved 3-4 Abstract Data Types • Information hiding – Hides certain implementation details within a module – Makes these details inaccessible from outside the module
  • 5. © 2005 Pearson Addison-Wesley. All rights reserved 3-5 Abstract Data Types Figure 3.1 Isolated tasks: the implementation of task T does not affect task Q
  • 6. © 2005 Pearson Addison-Wesley. All rights reserved 3-6 Abstract Data Types • The isolation of modules is not total – Functions’ specifications, or contracts, govern how they interact with each other Figure 3.2 A slit in the wall
  • 7. © 2005 Pearson Addison-Wesley. All rights reserved 3-7 Abstract Data Types • Typical operations on data – Add data to a data collection – Remove data from a data collection – Ask questions about the data in a data collection
  • 8. © 2005 Pearson Addison-Wesley. All rights reserved 3-8 Abstract Data Types • Data abstraction – Asks you to think what you can do to a collection of data independently of how you do it – Allows you to develop each data structure in relative isolation from the rest of the solution – A natural extension of procedural abstraction
  • 9. © 2005 Pearson Addison-Wesley. All rights reserved 3-9 Abstract Data Types • Abstract data type (ADT) – An ADT is composed of • A collection of data • A set of operations on that data – Specifications of an ADT indicate • What the ADT operations do, not how to implement them – Implementation of an ADT • Includes choosing a particular data structure
  • 10. © 2005 Pearson Addison-Wesley. All rights reserved 3-10 Abstract Data Types Figure 3.4 A wall of ADT operations isolates a data structure from the program that uses it
  • 11. © 2005 Pearson Addison-Wesley. All rights reserved 3-11 The ADT List • Except for the first and last items, each item has a unique predecessor and a unique successor • Head or front do not have a predecessor • Tail or end do not have a successor
  • 12. © 2005 Pearson Addison-Wesley. All rights reserved 3-12 The ADT List • Items are referenced by their position within the list • Specifications of the ADT operations – Define the contract for the ADT list – Do not specify how to store the list or how to perform the operations • ADT operations can be used in an application without the knowledge of how the operations will be implemented
  • 13. © 2005 Pearson Addison-Wesley. All rights reserved 3-13 The ADT List • ADT List operations – Create an empty list – Determine whether a list is empty – Determine the number of items in a list – Add an item at a given position in the list – Remove the item at a given position in the list – Remove all the items from the list – Retrieve (get) item at a given position in the list
  • 14. © 2005 Pearson Addison-Wesley. All rights reserved 3-14 The ADT List • The ADT sorted list – Maintains items in sorted order – Inserts and deletes items by their values, not their positions
  • 15. © 2005 Pearson Addison-Wesley. All rights reserved 3-15 The ADT List Figure 3.7 The wall between displayList and the implementation of the ADT list
  • 16. © 2005 Pearson Addison-Wesley. All rights reserved 3-16 Designing an ADT • The design of an ADT should evolve naturally during the problem-solving process • Questions to ask when designing an ADT – What data does a problem require? – What operations does a problem require?
  • 17. © 2005 Pearson Addison-Wesley. All rights reserved 3-17 Designing an ADT • For complex abstract data types, the behavior of the operations must be specified using axioms – Axiom: A mathematical rule – Ex. : (aList.createList()).size() = 0
  • 18. © 2005 Pearson Addison-Wesley. All rights reserved 3-18 Implementing ADTs • Choosing the data structure to represent the ADT’s data is a part of implementation – Choice of a data structure depends on • Details of the ADT’s operations • Context in which the operations will be used
  • 19. © 2005 Pearson Addison-Wesley. All rights reserved 3-19 Implementing ADTs • Implementation details should be hidden behind a wall of ADT operations – A program would only be able to access the data structure using the ADT operations
  • 20. © 2005 Pearson Addison-Wesley. All rights reserved 3-20 Implementing ADTs Figure 3.8 ADT operations provide access to a data structure
  • 21. © 2005 Pearson Addison-Wesley. All rights reserved 3-21 Implementing ADTs Figure 3.9 Violating the wall of ADT operations
  • 22. © 2005 Pearson Addison-Wesley. All rights reserved 3-22 C++ Classes • Encapsulation combines an ADT’s data with its operations to form an object – An object is an instance of a class – A class contains data members and member functions • By default, all members in a class are private
  • 23. © 2005 Pearson Addison-Wesley. All rights reserved 3-23 C++ Classes • Each class definition is placed in a header file – Classname.h • The implementation of a class’s member functions are placed in an implementation file – Classname.cpp
  • 24. © 2005 Pearson Addison-Wesley. All rights reserved 3-24 C++ Classes Figure 3.10 An object’s data and methods are encapsulated
  • 25. © 2005 Pearson Addison-Wesley. All rights reserved 3-25 Class Constructors and Destructors • Constructors – Create and initialize new instances of a class – Have the same name as the class – Have no return type, not even void
  • 26. © 2005 Pearson Addison-Wesley. All rights reserved 3-26 Class Constructors and Destructors • A class can have several constructors – A default constructor has no arguments – Initializers can set data members to initial values – The compiler will generate a default constructor if one is omitted
  • 27. © 2005 Pearson Addison-Wesley. All rights reserved 3-27 Class Constructors and Destructors • The implementation of a constructor (or any member function) is qualified with the scope resolution operator :: Sphere::Sphere(double initialRadius) : theRadius(initialRadius)
  • 28. © 2005 Pearson Addison-Wesley. All rights reserved 3-28 Class Constructors and Destructors • Destructors – Destroy an instance of an object when the object’s lifetime ends • Each class has one destructor – For many classes, the destructor can be omitted – The compiler will generate a default constructor if one is omitted
  • 29. © 2005 Pearson Addison-Wesley. All rights reserved 3-29 Inheritance in C++ • A derived class or subclass inherits any of the publicly defined functions or data members of a base class or superclass
  • 30. © 2005 Pearson Addison-Wesley. All rights reserved 3-30 Inheritance in C++ • An instance of a derived class can invoke public methods of the base class: #include “Sphere.h” enum Color {RED, BLUE, GREEN, YELLOW} class ColoredSphere: public Sphere { public: … Color getColor() const; …
  • 31. © 2005 Pearson Addison-Wesley. All rights reserved 3-31 C++ Namespaces • A mechanism for logically grouping declarations and definitions into a common declarative region
  • 32. © 2005 Pearson Addison-Wesley. All rights reserved 3-32 C++ Namespaces • The contents of the namespace can be accessed by code inside or outside the namespace – Use the scope resolution operator to access elements from outside the namespace – Alternatively, the using declaration allows the names of the elements to be used directly
  • 33. © 2005 Pearson Addison-Wesley. All rights reserved 3-33 C++ Namespaces • Creating a namespace namespace smallNamespace { int count = 0; void abc(); } //end smallNamespace • Using a namespace using namespace smallNamespace; count +=1; abc();
  • 34. © 2005 Pearson Addison-Wesley. All rights reserved 3-34 C++ Namespaces • Items declared in the C++ Standard Library are declared in the std namespace • C++ include files for several functions are in the std namespace – To include input and output functions from the C++ library, write include <iostream> using namespace std;
  • 35. © 2005 Pearson Addison-Wesley. All rights reserved 3-35 An Array-Based ADT List • A list’s items are stored in an array items • Both an array and a list identify their items by number
  • 36. © 2005 Pearson Addison-Wesley. All rights reserved 3-36 An Array-Based ADT List • A list’s kth item will be stored in items[k- 1] Figure 3.11 An array-based implementation of the ADT list
  • 37. © 2005 Pearson Addison-Wesley. All rights reserved 3-37 C++ Exceptions • Exception – A mechanism for handling an error during execution – A function indicates that an error has occurred by throwing an exception – The code that deals with the exception is said to catch or handle it
  • 38. © 2005 Pearson Addison-Wesley. All rights reserved 3-38 C++ Exceptions • Throwing exceptions – A throw statement is used to throw an exception throw ExceptionClass (stringArgument);
  • 39. © 2005 Pearson Addison-Wesley. All rights reserved 3-39 C++ Exceptions • try block – A statement that might throw an exception is placed within a try block – Syntax try { statement(s); } // end try
  • 40. © 2005 Pearson Addison-Wesley. All rights reserved 3-40 C++ Exceptions • catch block – Used to catch an exception and deal with the error condition – Syntax catch (exceptionClass identifier) { statement(s); } // end catch
  • 41. © 2005 Pearson Addison-Wesley. All rights reserved 3-41 C++ Exceptions • A programmer-define ListException class #include <exception> #include <string> using namespace std; class ListException: public exception { public: ListException (const string & message = “”) : exception(message.c_str()) {} }; // end ListException
  • 42. © 2005 Pearson Addison-Wesley. All rights reserved 3-42 Summary • Data abstraction controls the interaction between a program and its data structures • Abstract data type (ADT): a set of data- management operations together with the data values upon which they operate • Mathematical study of ADTs uses axioms to specify the behavior of ADT operations • An ADT should be fully defined before any implementation decisions
  • 43. © 2005 Pearson Addison-Wesley. All rights reserved 3-43 Summary • Hide an ADT’s implementation by defining the ADT as a C++ class • An object encapsulates both data and operations • A class contains at least one constructor and a destructor • The compiler generates default constructor and destructor if none are provided
  • 44. © 2005 Pearson Addison-Wesley. All rights reserved 3-44 Summary • Members of a class are private by default – Data members are typically private – Public functions can be provided to access them • Define and implement a class within header and implementation files • Namespace: a mechanism to group classes, functions, variables, types, and constants • Use exception handling to throw, catch, and handle errors during program execution