Object-Oriented Programming Flashcards

(36 cards)

1
Q

What is a class?

A

The definition of an object. Classes define the attributes and methods that an object of the class will have.

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

What is an object?

A

A specific instance of a class

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

What is instantiation?

A

The process of creating an instance of an object, belonging to a class, by invoking a constructor method

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

What is encapsulation? (in terms of OOP)

A

Combing data with the procedures and functions that manipulate it to form a new data type (class)

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

What is information hiding in oop?

A

Protects an object’s implementation and internal state from being accessed by other objects

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

What are the uses of information hiding?

A

Allows programmers to implement restrictions on how values are accessed and set. This is done through the use of access modifiers.

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

What are the access modifiers and their descriptions?

A
  • Public: accessed by objects of any other class (+)
  • Private: accessed only by objects of that class (-)
  • Protected: accessed by other objects of the class or subclass (#)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a getter method?

A

A method that returns the requested attribute value

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

What is a setter method?

A

A method that can modify the attribute’s value

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

Why do we use getters and setters?

A

They allow developers to implement additional checks before accepting or providing data.

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

What is polymorphism?

A

When objects of different classes respond differently to the use of a common interface

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

What is polymorphism in OOP?

A

Polymorphism occurs when an inherited method (in a subclass) is redefined or overriden so that its implementation is different from its parent

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

What is the interface?

A

The collection of a classes public methods, attributes and its identifier

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

What is overriding?

A
  • When a method is defined in a derived class with the same identifier as a method from the base class but is given a different implementation/ performs a different function
  • Redefined method will be used instead of the base’s method when called
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are methods that can be overridden by a derived class called?

A

Virtual methods

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

What does an abstract method define?

A

The interface:
- identifier
- return type
- list of parameters

17
Q

What are the differences between a virtual and abstract class?

A
  • Virtual methods can be overridden by a child class but abstract must be overridden by a child class
  • Virtual have an implementation in base class but abstract do not
  • Virtual can be declared in any class but abstract can only be defined in abstract classes
18
Q

What is object association?

A

Occurs when an object contains or has a reference to another object within it. Often described as a “has a” relationship.

19
Q

What are the two forms of association?

A
  • Composition - “strong”
  • Aggregation - “weak”
20
Q

What is composition?

A

Composition is a restricted form of association, where one object contains another. If the container object is deleted, the contained objects are also deleted.

21
Q

How is composition represented in a UML diagram?

A

A line between the two classes with a black filled diamond at the class which is the container (e.g. car to a wheel)

22
Q

What is aggregation?

A

Type of relationship where one class contains another class.However, the aggregated objects exist independently of the aggregating object and will not be deleted from the program if the aggregating object is deleted.

23
Q

How is aggregation represented in a UML diagram?

A

A line between the two classes and a white unfilled diamond at the aggregating object (e.g. car for a driver).

24
Q

What is inheritance?

A

Describes the relationship between classes where a derived “child” class gains the attributes and methods from a “parent” class

25
How do you represent inheritance in a UML class diagram?
A filled arrow going from the derived class to the base class
26
What are the 3 OOP design principles?
1. Encapsulate what varies 2. Favour composition over inheritance 3. Program to the interface, not implementation
27
What is inheritance in object-oriented programming?
A relationship between classes where a derived class gains the attributes and methods of the base class that it inherits from
28
What does the design principle “encapsulate what varies” mean?
- Encapsulate parts of our program that frequently changed or updated into classes - Ensures modules are loosely-coupled - Modifications can be tested within the class itself and has minimal impact on the rest of the program
29
What does the design principle “favour composition over inheritance” mean?
- Composition isn more flexible and allows for complex functionalities by combining component objects - If class A requires functionality of class B, it is best to give class A an instance of class B rather than inheriting from it
30
What does the design principle “program to the interface, not implementation” mean?
- To write loosely-coupled code our objects should be designed to only interact with other objects via their interface - This allows for implementation to be changed without affecting the rest of the program
31
What are the access modifiers and how can they be represented in UML diagrams?
Public: + Private: - Protected: #
32
What does the public access modifier mean?
Attribute or method can be accessed by objects of any other class within the program
33
What does the private modifier mean?
Attribute or method can only be accessed by objects of the same class
34
What does the protected modifier mean?
Attribute or method can be accessed by objects of the same class **or other classes that inherit from it**
35
What are static methods?
Class methods that can be called without the need to **instantiate an object** of that class // A method that doesn't rely on the **internal state** of a specific **object** of the class.
36
What are the uses of static variables?
- Only stored once per class so less memory used - Autoincrementing between objects (e.g. for an ID)