Object-Oriented Programming Flashcards

(30 cards)

1
Q

What is object-oriented programming?

A

An entirely modular to programming where everything in the program is implemented as an object which has attributes and properties (data) and methods (subroutines)

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

What is encapsulation?

A

Data and subroutines for a single object are kept together and the data is controlled via methods that comprise the object’s interface

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

What is a class?

A

The definition that continues what attributes and methods an object will have

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
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
5
Q

What is encapsulation in terms of object-oriented programming?

A

Combining a record 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
6
Q

What is the constructor of a class?

A

The method called to instantiate an object of that class. There is an object that is returned from this and it can be stored in a variable

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

What is information hiding?

A

Protecting an object’s internal state from being accessed by other parts of the program

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

What are the access modifiers and how can they be represented in UML diagrams?

A

Public: +
Private: -
Protected: #

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

What does the public access modifier mean?

A

Attribute or method can be accessed by objects of any other class within the program

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

What does the private modifier mean?

A

Attribute or method can only be accessed by objects of the same class

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

What does the protected modifier mean?

A

Attribute or method can be accessed by objects of the same class or other classes that inherit from it

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

What is the format of a formal class definition?

A

ClassIdentifier = Class
Public
public attributes : types
public methods and procedures
Protected
protected attributes : types
protected methods
Private
private attributes : types
private methods
End

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

What is the default for attributes and methods?

A

Private attributes and public getter methods

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

What is inheritance in object-oriented programming?

A

A relationship between classes where a derived class gains the attributes and methods of the base class that it inherits from

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

How to represent inheritance in a UML diagram?

A

Arrow pointing from derived to base class

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

How to represent inheritance in a formal class definition?

A

DerivedClassIdentifier = Class (BaseClassIdentifier)

  • only give additional methods in the definition or overriden methods
17
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

18
Q

What is polymorphism (AQA definition)?

A

Polymorphism occurs when objects of different classes respond differently to the use of a common interface

19
Q

What are virtual methods?

A

Methods that can be overriden in inheritance

20
Q

What is method overriding?

A

Derived class inherits a method from the base class but implements it in a different way

21
Q

What are the key differences between virtual and abstract methods?

A

Virtual methods:
- Can be overridden by a child class
- Are implemented
- Can be declared in any class

Abstract methods:
- Must be overridden by a child class
- Have no implementation in the parent class
- Can only be declared in abstract classes

22
Q

How to declare an abstract class in C# and abstract method?

A

Abstract keyword

23
Q

What are the two types of association?

A

1) Aggregation - “weak”
2) Composition - “strong”

24
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.

25
How is composition represented in a UML diagram?
A line between the two classes with a **black filled diamond** at the class which is the container (e.g. car to a wheel)
26
What is aggregation?
Aggregation is a type of class where one class contains another. However, the **aggregated** objects exist **independently** of the aggregating object and will **not be deleted** from the program if the **aggregating object is deleted**.
27
How is aggregation represented in a UML diagram?
A line between the two classes and a **white unfilled diamond** at the aggregating object (e.g. car for a driver).
28
What are the key design principles in object-oriented programming?
1) Encapsulate things that frequently change 2) Favour composition over inheritance 3) Program to interfaces, not implementations
29
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.
30
What are the uses of static variables?
- Only stored once per class so less memory used - Autoincrementing between objects (e.g. for an ID)