PL PreFi

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

1/23

flashcard set

Earn XP

Description and Tags

The italic part of the definition is from chatgpt

Last updated 8:10 AM on 5/5/25
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

24 Terms

1
New cards

Abstraction

  • A view or representation of an entity that includes only the most significant attributes

  • Nearly all programming languages support it

    • it is the practice of hiding complex details and showing only the essential features of an object or function, helps manage complexity by breaking down a program into more understandable and manageable parts

2
New cards

Abstract Data Type

It is a user-defined data type that satisfies the following 2 conditions:

  • 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

    • this means that the internal structure (like arrays, pointers, or variables) is not visible to the code that uses the data type

    • users of this data type can only interact with it using predefined operations like add(), remove(), get()

  • The declarations of the type and the protocols of the operations on objects of the type are contained in a single syntactic unit. Other program units are allowed to create variables

    • this means that the definition of the data type and the functions that work on it are grouped together

    • only the other parts of your code can use this type (like creating variables of it), but can’t change its internal behavior

      • it is a logical description of a data structure that defines the operations that can be performed on it, without specifying how those operations are implemented. It focuses on what the data structure does rather than how it does it

3
New cards

Data Abstraction Advantages

  • 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

  • Less to keep track of—Reduces the range of code and variables of which the programmer must be aware

  • Name conflicts are less likely

  • Better organization—Provides a method of program organization

  • Easier to update or modify—Aids modifiability (everything associated with a data structure is together)

  • Separate compilation

4
New cards

ADT Requirements

  • A syntactic unit in which to encapsulate the type definition

    • The language must allow you to group the data and the functions that operate on that data into one unit

  • A method of making type names and subprogram headers visible to clients, while hiding actual definitions

    • The language allow you to expose only the interface (what the ADT does), while hiding the implementation

    • This is usually done using access modifiers

      • public: visible to other parts of the program

      • private: hidden from the outisde

  • Some primitive operation must be built into the language processor

    • The language must support basic built-in operations that ADTs rely on such as memory management, assignment, equality checks, data access or copying

5
New cards

ADT Design Issues

  • Can abstract types be parameterized?

    • Can you make an ADT work with different data types?

  • What access controls are provided?

    • Can you control which parts of your ADT are visible or hidden from the outside world?

  • Is the specification of the type physically separate from its implementation?

    • Can you keep the interface (what the ADT does) separate from the implementation (how it does it)?

6
New cards

C++ ADT

  • Based on C struct and Simula 67 classes

  • The class is the encapsulation device

  • A class is a type

  • All of the class instances of a class share a single copy of the member functions

  • Each instance of a class has its own copy of the class data members

  • Instances can be static, stack dynamic, or heap dynamic

7
New cards

C++ Information Hiding

  • private: Only Accessible inside the class

  • public: Accessible from anywhere (interface)

  • protected: Accessible inside the class and by subclass (for inheritance)

8
New cards

C++ Constructors

  • Functions to initialize the data members of instances (they do not create the objects)

    • The object is created by the compiler or new keyword — the constructor just sets it up, like assigning default values or allocating memory

  • May also allocate storage if part of the object is heap-dynamic

    • If the class needs extra memory (e.g., creating a dynamic array), the constructor can use new to allocate that memory

  • Can include parameters to provide parameterization of the objects

    • You can pass arguments into a constructor to customize how the object is set up

  • Implicitly called when an instance is created

    • You don’t have to call the constructor manually—it automatically runs when you create an object like Stack s;

  • Can be explicitly called

  • Name is the same as the class name

    • The constructor must have the exact same name as the class and has no return type

9
New cards

C++ Destructors

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

    • When an object is no longer needed, the destructor frees memory or other resources

  • Implicitly called when the object’s lifetime ends

    • You don’t need to call the destructor manually—it’s automatically triggered when the function ends or when delete is used

  • Can be explicitly called

    • Very rare, but you can call it manually like obj.~ClassName();

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

10
New cards

C++ Friend Function

  • It provides access to private members to some unrelated units or functions

    • It is a function or a class that is allowed to access the private and protected members of another class, even tho it’s not a member of that class

    • You need to use it when you have two classes that need to work closely together, or you have an external function that needs to inspect or modify private data of a class

11
New cards

Java ADT

  • Similar to C++ except:

    • All user-defined types are classes

      • Everything you define is a class—you can’t define standalone structs or global functions like in C++

    • All objects are allocated from the heap and accessed through reference variables

      • When you create an object with new, it always lives in the heap, and you interact with it using references

    • Individual entities in classes have access control modifiers (private or public), rather than clause

      • Access control is done on a per-variable or method level, not in blocks

    • Implicit garbage collection of all objects

      • It automatically cleans up unused objects via garbage collection—no need to manually delete or write destructors like in C++

    • It has a second scoping mechanism, package scope, which can be used in place of friends

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

        • It has no friend keyword like C++, but it has package-private access—where classes in the same package can access each other’s members if no modifier is specified.

12
New cards

C# ADT

  • Based on C++ and Java

  • Adds two access modifiers, internal and protected internal

    • internal is accessible only within the same assembly/project and protected internal is accessible to subclasses or same-assembly code

  • All class instances are heap dynamic

    • Every time you create an object, it is stored on the heap

  • Default constructors are available for all classes

    • If you don’t define a constructor, C# automatically provides a no-argument constructor

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

    • It has an automatic garbage collector

  • struct are lightweight classes that do not support inheritance

13
New cards

Accessor Methods

  • Getters and Setters

    • To need for access to data members

      • A common solution to safely access private data members

14
New cards

C# Properties

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

    • C# can let you create this that look like variables, but act like getter/setter methods behind the scenes

15
New cards

Parameterized ADT

  • It allows designing an ADT that can store any type elements — only an issue for static typed languages

  • Also known as generic classes

    • It is a data structure that can work with any data type—like int, float, string—without rewriting the ADT

      • A generic Stack that works for int, string, or Student objects

16
New cards

C++ Parameterized ADT

  • Classes can be somewhat generic by writing parameterized constructor functions

    • This means you can customize the behavior of a class at runtime by passing arguments to its constructor—like setting the size of a stack

17
New cards

Java Parameterized ADT

  • Generic parameters must be classes

    • Generics can only use reference types (classes)—not primitive types like int, double, etc.

  • Most common generic types are the collection types, such as LinkedList and ArrayList

  • Eliminate the need to cast objects that are removed

  • Eliminate the problem of having multiple types in a structure

    • With generics, you could prevent adding a different type to one collection by providing a compile-time error

  • Users can define generic classes

  • Generic collection classes cannot store primitives

  • Indexing is not supported

18
New cards

C# Parameterized Classes

  • Similar o Java, except no wildcard classes

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

    • Has built-in generic collections

  • Elements of parameterized structures can be accessed through indexing

19
New cards

Encapsulation

  • A grouping of subprograms that are logically related into a unit that can be separately compiled

    • It is the concept of wrapping data and behavior together in a single unit for better code organization, independent compilation and reuse

20
New cards

Nested Subprograms

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

    • It is a function or method that is defined inside another function

21
New cards

C Encapsulation

  • Files containing one or more subprograms can be independently compiled

    • It allows you to split a program into multiple .c files and compile them separately which supports modular programming

  • The interface is placed in a header file

    • The header file .h contains function declarations, constants, macros, and type definitions— the public interface of a module

  • Problem1: the linker does not check types between a header and associated implementation

    • If the function signature in the .c file doesn’t match the header file, the linker won’t catch it—the error may appear only at runtime, leading to bugs

  • Problem2: the inherent problems with pointers

    • it can cause memory leaks, crashes, complicates encapsulation,

  • #include preprocessor specification—used to include header files in application

    • The #include directive copes the contents of a header file into the source file before compilation

22
New cards

C++ Encapsulation

  • Can define header and code files, similar to C

  • Or, classes can be used for encapsulation

    • The class is used as the interface (prototypes)

    • The member definitions are defined in a separate file

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

23
New cards

Concurrency Categories

  • Physical concurrency

  • Logical Concurrency

24
New cards

Physical Concurrency

  • Multiple independent processors (multiple threads of control)