Abstract Data Types and Encapsulation Concepts

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/55

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

56 Terms

1
New cards

abstraction

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

2
New cards

concept of abstraction

is fundamental in programming (and computer science)

3
New cards

process abstraction with subprograms

Nearly all programming languages support

4
New cards

data abstraction

Nearly all programming languages designed since 1980 support

5
New cards

abstract data type

a user-defined data type that satisfies the following two conditions

6
New cards

hidden from the program units

type's definition

abstract data type condition:

The representation of objects of the type is — that use these objects, so the only operations possible are those provided in the —

7
New cards

single syntactic unit

abstract data type condition:

The representation of, and operations on, objects of the type are defined in a —

8
New cards

Reliability

Advantage of the first condition

  • 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

9
New cards
  • Program organization

  • modifiability

  • separate

Advantage of the second condition

  • Provides a method of —

  • aids — (everything associated with a data structure is together)

  • — compilation

10
New cards

type definition

Language Requirements for ADTs

A syntactic unit in which to encapsulate the —

11
New cards
  • A syntactic unit to define an ADT

  • Built-in operations

  • Common operations

  • Parameterized ADTs

Design Issues (4)

12
New cards

  • Assignment

  • Comparison

Design Issues: 2 Built-in operations

13
New cards
  • Accessors

  • Constructors

  • Destructors

Design Issues: 3 Common operations

14
New cards

packages

  • Specification package

  • Body package

Language Examples: Ada

The encapsulation construct is called —

  • — (the interface)

  • — (implementation of the entities named in the specification)

15
New cards
<ul><li><p>private part </p></li></ul><ul><li><p>no built-in operations</p></li></ul><ul><li><p>pointer </p></li></ul><ul><li><p> pointed-to structure's definition</p></li></ul><p></p>
  • private part

  • no built-in operations

  • pointer

  • pointed-to structure's definition

Language Examples: Ada

Two ways for Information Hiding

  • The representation of type appears in a part of the specification called the —

    • More restricted form with limited private types: objects of this type have —

  • Define the ADT as a — and provide the — in the body package, whose entire contents are hidden from clients.

16
New cards
  • C struct type and Simula 67 classes

  • encapsulation device

  • member functions

  • class data members

  • static, stack dynamic, or heap dynamic

Language Examples: C++

  • Based on (2)

  • The class is the —

  • All of the class instances of a class share a single copy of the —

  • Each instance of a class has its own copy of the —

  • Instances can be (3)

<p><span><strong>Language Examples: C++ </strong></span></p><ul><li><p><span>Based on (2)</span></p></li><li><p><span>The class is the —</span></p></li><li><p><span> All of the class instances of a class share a <strong>single copy</strong> of the —</span></p></li><li><p><span>Each instance of a class has its o<strong>wn copy</strong> of the —</span></p></li><li><p><span>Instances can be (3)</span></p></li></ul><p></p>
17
New cards
  • hidden entities

  • interface entities

  • inheritance

Information Hiding:

  • Private clause for —

  • Public clause for —

  • Protected clause for —

18
New cards

Constructors

Language Examples: C++

  • Name is the same as the class name

  • Implicitly called when an instance is created

the objects)

<p><strong>Language Examples: C++</strong></p><p>—</p><ul><li><p>Name is the same as the class name</p></li><li><p>Implicitly called when an instance is created</p></li></ul><p>the objects)</p><p></p>
19
New cards
  • data members of instances

  • heap-dynamic

  • parameters

Constructors:

  • initialize the — (they do not create the objects

  • May also allocate storage if part of the object is —

  • Can include — to provide parameterization of the objects

20
New cards

Destructors

  • lifetime ends

  • cleanup

Language Examples: C++

  • Name is the class name, preceded by a tilde (~)

  • Implicitly called when the object's —

  • — after an instance is destroyed; usually just to reclaim heap storage

21
New cards

Friend functions or classes -

Language Examples: C++

— to provide access to private members to some unrelated units or functions

  • Necessary in C++

22
New cards
  • circularly linked list

  • push

  • put

  • class Cell

Language Examples: C++

  • The class List defines a —

    • —: add to the front

    • —: add at the back

  • The — is used to form lists.

<p><strong>Language Examples: C++</strong></p><ul><li><p>The class List defines a —</p><ul><li><p>—: add to the front </p></li><li><p>—: add at the back </p></li></ul></li><li><p>The — is used to form lists.</p></li></ul><p></p>
23
New cards
<p>class cell</p>

class cell

Language Examples: C++

class list

<p><strong>Language Examples: C++</strong></p><p>class list</p>
24
New cards

Java

  • classes

  • heap - reference variables

Language Examples: —

Similar to C++, except:

  • All user-defined types are —

  • All objects are allocated from the — and accessed through —

<p><strong>Language Examples: —</strong></p><p>Similar to C++, except:</p><ul><li><p>All user-defined types are —</p></li><li><p>All objects are allocated from the — and accessed through —</p></li></ul><p></p>
25
New cards
  • access control modifiers (private or public) - clauses

Language Examples: Java

Similar to C++, except:

  • Individual entities in classes have—, rather than —

26
New cards
  • second scoping mechanism, package scope,

  • visible

Language Examples: Java

Similar to C++, except:

  • Java has a — which can be used in place of friends

    • All entities in all classes in a package that do not have access control modifiers are — throughout the package

27
New cards

C#

  • internal and protected internal

  • heap dynamic

Language Examples: —

  • Based on C++ and Java

  • Adds two access modifiers, —

  • All class instances are —

28
New cards

C#

  • Default constructors

  • Garbage collection

  • structs

Language Examples: C#

  • — are available for all classes

  • — is used for most heap objects, so destructors are rarely used

  • — are lightweight classes that do not support inheritance

29
New cards
<ul><li><p>accessor methods (getter and setter) </p></li></ul><ul><li><p>properties </p></li></ul><p></p>
  • accessor methods (getter and setter)

  • properties

Language Examples: C#

  • Common solution to need for access to data members: —

  • C# provides —as a way of implementing getters and setters without requiring explicit method calls

30
New cards

Parameterized Abstract Data Types

  • allow designing an ADT that can store any type elements

    • only an issue for static typed languages

31
New cards
  • generic classes

  • C++, Java 5.0, and C# 2005

Parameterized Abstract Data Types

  • Also known as —

  • (3) provide support for parameterized ADTs

32
New cards
<ul><li><p>parameterized constructor functions</p></li><li><p>Stack stk(150);</p></li></ul><p></p>
  • parameterized constructor functions

  • Stack stk(150);

Parameterized ADTs in C++

  • Classes can be somewhat generic by writing —

  • A declaration of a stack object:

33
New cards
<p>templated class</p><p>Stack myIntStack;</p>

templated class

Stack myIntStack;

Parameterized ADTs in C++

The stack element type can be parameterized by making the class a —

Instantiation: —

34
New cards

Java 5.0

  • classes

  • collection types

  • LinkedList and ArrayList

Parameterized Classes in —

  • Generic parameters must be —

  • Most common generic types are the —, such as —

  • Eliminate the need to cast objects that are removed

  • Eliminate the problem of having multiple types in a structure

  • Users can define generic classes

  • Generic collection classes cannot store primitives

  • Indexing is not supported

35
New cards
  • cast objects

  • multiple types in a structure

Parameterized Classes in Java 5.0

  • Eliminate the need to — that are removed

  • Eliminate the problem of having —

36
New cards
  • Users

  • primitives

  • Indexing

Parameterized Classes in Java 5.0

  • — can define generic classes

  • Generic collection classes cannot store —

  • — is not supported

37
New cards
<p>myArray.add(0, 47); // Put an element with subscript 0 in it</p>

myArray.add(0, 47); // Put an element with subscript 0 in it

Parameterized Classes in Java 5.0

Example of the use of a predefined generic class:

ArrayList myArray = new ArrayList ();

38
New cards
<p>Stack2 myStack = new Stack2 ();</p>

Stack2 myStack = new Stack2 ();

Parameterized Classes in Java 5.0

Instantiation:

39
New cards

C# 2005

Parameterized Classes in —

  • Similar to those of Java 5.0, except no • Predefined for Array, List, Stack, Queue, and Dictionary • Elements of parameterized structures can be accessed through indexing

40
New cards

C# 2005

  • wildcard classes

Parameterized Classes in —

  • Similar to those of Java 5.0, except no —

  • Predefined for Array, List, Stack, Queue, and Dictionary

  • Elements of parameterized structures can be accessed through indexing

41
New cards
  • Array, List, Stack, Queue, and Dictionary

  • indexing

Parameterized Classes in C#2005

  • Predefined for (5)

  • Elements of parameterized structures can be accessed through —

42
New cards

Encapsulation Constructs

  • means of organization

  • means of partial compilation

  • Large programs have two special needs:

    • Some —, other than simply division into subprograms

    • Some — (compilation units that are smaller than the whole program)

43
New cards
  • separately compiled

  • encapsulation

Encapsulation Constructs

  • Obvious solution: a grouping of subprograms that are logically related into a unit that can be — (compilation units)

  • Such collections are called —

44
New cards

Nested Subprograms

  • Python, JavaScript, and Ruby

  • Organizing programs by — definitions inside the logically larger subprograms that use them

  • are supported in (3)

45
New cards

C

  • independently compiled

  • header file

Encapsulation in —

  • Files containing one or more subprograms can be —

  • The interface is placed in a —

46
New cards
  • linker

  • pointers

Encapsulation in C

  • Problem 1: the — does not check types between a header and associated implementation

  • Problem 2: the inherent problems with —

  • #include preprocessor specification – used to include header files in applications

47
New cards
  • #include preprocessor specification

Encapsulation in C

  • — used to include header files in applications

48
New cards

C++

  • header and code files

  • encapsulation

  • interface (prototypes)

Encapsulation in —

  • Can define —, similar to those of C

  • Or, classes can be used for —

  • The class is used as the —

49
New cards
  • member definitions

  • Friends

Encapsulation in C++

  • The — are defined in a separate file

  • — provide a way to grant access to private members of a class

50
New cards

C# Assemblies

  • single dynamic link library or executable

  • separately compiled

  • A collection of files that appears to application programs to be a —

  • Each file contains a module that can be —

51
New cards
  • DLL

  • internal

  • internal member

C# Assemblies

  • A — is a collection of classes and methods that are individually linked to an executing program

  • C# has an access modifier called —;

  • an — of a class is visible to all classes in the assembly in which it appears

52
New cards
  • global names

  • logical groupings

Naming Encapsulations

  • Large programs define many —; need a way to divide into —

53
New cards

naming encapsulation

  • C++ Namespaces

  • C#

A — is used to create a new scope for names

  • – Can place each library in its own namespace and qualify names used outside with the namespace

  • — also includes namespaces

54
New cards
  • Java Packages

  • partial friends

  • fully qualified name

Naming Encapsulations

  • — Packages can contain more than one class definition; classes in a package are —

  • Clients of a package can use — or use the import declaration

55
New cards
  • Ruby classes

  • modules

  • constants and methods

Naming Encapsulations

  • — are name encapsulations, but Ruby also has —

  • Typically encapsulate collections of —

  • Modules cannot be instantiated or subclassed, and they cannot define variables

  • Methods defined in a module must include the module’s name

  • Access to the contents of a module is requested with the require method

56
New cards