Object Oriented Programming Flashcards

1
Q

Derived Classes/Child Classes

A

An EXTENSION of a base class Classes that inherit functions and variables from a base class
aka “child” class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Base class/Parent Class

A

Class that can be EXTENDED by a derived class.
Includes functions and variables that can be inherited by a derived class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Inheritance

A

Mechanism for EXTENDING a class
-If you extend the class rather than editing it, you will not have to “re-debug” the original code (because it was not changed since the last time you debugged)
-It allows you to reuse existing DEBUGGED code by allowing a class to acquire properties (data and operations) of another class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Multiple Inheritance

A

Inheritance of properties from multiple classes
-Generally not recommended, but some languages (like C++) will allow it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

“Public”

A

Indicates that the data/operation can interface with the rest of the world
can be accessed from outside of the class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

“Private”

A

Indicates that the data/operation can only interface with member functions of the class in which it was written

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

“Protected”

A

Indicates that the data/operation can ONLY interface with the data/operations of a derived class
DO NOT USE THIS UNLESS YOU KNOW THE CLASS IS GOING TO BE INHERITED (otherwise you can get yourself in trouble when it comes to debugging)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Practical applications of inheritance

A
  1. Principle of Least Privilege & Role-based access control
    The most general base class should have the fewest permissions. As the roles become more specific, they are given more and more privileges.
    2.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Reading a class block in a class diagram

A

Minus (-) inidicates private.
Plus (+) indicates public.
Pound sign (#) indicates “protected”.
The name of the class goes in the top box.
The data/variables of the class go in the middle box.
The operations/functions of the class go in the bottom box.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Inheriting “private” variables/function

A

Private members of the Base Class are present within objects of the Derived Class but are NOT directly accessible within the Derived Class code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Constructors

A

Constructors are not inherited.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Representing a derived class in a UML class diagram

A

Only show what is EXCLUSIVE to the derived class.
NEW variables
NEW functions
Anything that is overwritten

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Memory handling of inheritance

A

When you create a child class, you are also “creating” a parent class inside of that child class. There is a Base class object nested within each Derived class object. The base class object literally comes directly before the derived class in memory. The Base class object “contains” all inherited members

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Accessing private members of the base class

A

If the derived class inherits PUBLIC functions from the base class…. then those functions can still access the private variables of the base class via that public function it just inherited

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Constructor inheritance

A

No such thing. Derived classes do not inherit the constructor from the base class.
You will have to make a new constructor for the derived class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Order in which the destructors are called

A

Destructors are called in the upward inheritance order (less abstract constructors come first) Derived class destructors will be called before the base class destructor.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Parameters

A

Parameters are needed in the function header. It is a DECLARATION of variables that you can expect to find in that function. They require datatypes just like any declaration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Order in which the constructors are called

A

Constructors are called in the downward inheritance order (more abstract constructors come first) Base class constructors are called before the derived class constructors.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Arguments

A

Arguments are needed when the function is CALLED. They represent actual variable names so that you can pass actual values to the function. They do not require datatypes

20
Q

Calling a function from the based class inside a function of the same name within the derived class

A

This is completely legal. But it you must specify the location of the function you are calling (in C++ this is done using:
base_name::function_name

21
Q

What is the purpose/role of the constructor?

A

lol

22
Q

What is the purpose/role of the destructor?

A

lol

23
Q

What is the sequence of steps the machine goes through when it executes a program that includes both a base class AND a derived class that extends that base class?

A
24
Q

Purpose of the #ifndef guard?

A

You NEED it to keep the code from redundant imports. You do not want to import the same file more than once and if you use multiple sourcecode files, it is extremely likely that you have importanted something more than once because some files (like iostream string.h) are included in almost every C++ program

25
Q

Static Binding

A

Mean that something is decided how it behaves when you WRITE the code.
Compile-time determination of which function to call for a particular object

26
Q

Dynamic Binding

A

Means that something is decided how it behaves when you EXECUTE the code.
Run-time determination of which function to call for a particular object

27
Q

Polymorphism

A

The ability to determine which of several operations with the same name is appropriate

28
Q

Polymorphic Operation

A

An Operation that has multiple meanings depending upon the data type of the object to which it is bound at run time

29
Q

Abstract Data Type

A

Data type whose properties (domain and operations) are specified independently of any implementation

30
Q

Class

A

–A structured type used to model abstract data types
–Encapsulate attributes (data) with the member functions that modify
the attribute values

31
Q

Object

A

–An instance of a class
–Set of attribute values define the state of an object at a given time
–Member functions and attributes accessed using the member
selection operator (period .)

32
Q

Client

A

–Software that declares and manipulates objects of a particular class
type

33
Q

public members of a class

A

Can be accessed from outside of the class

34
Q

private members of a class

A

Accessible only by the code within the implementation file and is not accessible by
code outside of the class
- Client cannot interact directly with private
variables or functions within object

35
Q

Specification file

A

*The declaration of the class type
*Include guards (more on this later)

36
Q

Implementation File

A

*Code that implements the member functions of the class

37
Q

Unit Testing

A
  • Performed with a
    dedicated driver program
    –Contains a simplified main function that creates instances
    of the class (objects) and then tests the objects by using its
    public interface
    –Multiple source files must be compiled and linked to create
    the executable
    –Once tested, the class may be reused with the actual
    application program
38
Q

struct v. class

A

–A struct is a class whose members are public by default
–By default, all members of a C++ class are private
–Two built-in operations for structs and classes “.” and “=”

39
Q

Five categories of member functions

A
  1. Constructors
  2. Transformers
  3. Observers
  4. Iterators
  5. Destructors
40
Q

Constructor functions in a C++ class

A

Create and Initialize Object
Constructor methods have the same name as the class

41
Q

Transformers functions in a C++ class

A

Alter the state of an object

42
Q

Observer functions in a C++ class

A

Allow one to view the state of an object

43
Q

Iterator functions in a C++ class

A

Allow us to process (one at a time) all components of an ADT

44
Q

“const” for member functions

A

Member functions applied to an object may alter attributes stored within that object unless the reserved word const is used to prevent modification

45
Q

“self” for member functions

A

The object to which a member function
is applied