Fundamentals of Programming - Notes Flashcards

1
Q

How are stack frames used by computers

A

To store return address, parameters and local variables for each subroutine call that occurs during the execution of a program

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

How does exception handling work

A

-When an error occurs, the computer has to handle that error to avoid crashing
-It pauses execution and saving the current state of the program
-Runs the catch block of code
-Once error has been handled, the program restores its previous state before resuming execution

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

When does polymorphism occur

A

When a method in an object is processed differently depending on the class

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

Two types of association:

A

Aggregration and Composition

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

Relationship of Aggregration

A

Weak as an associated object will still exist when an object is deleted

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

Relationship of Composition

A

Strong as when an object is deleted, the associated object is also deleted

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

Whats an abstract method

A

Declared in the abstract class and do not have an implementation, they serve as a blueprint for methods that must be implemented by a subclass. Ensuring consistency between different subclasses.

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

Whats a virtual method

A

Methods in a base class that can be overriden by derived classes. They faciliate polymorphism, enabling method behaviour to vary based on the objects that invokes the method.

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

Encapsulate what varies definition

A

When designing a program, any requirements which are likely to change in the future should be encapsulated in a class so that any changes can be easily made when required

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

Favour composition over inheritance

A

Wherever possible, composition should be used over inheritance as composition is seen to have a more flexible relationship over objects

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

Program to interfaces, not implementation

A

This design principle allows unrelated classes to make use of similar methods. An interface is defined as a collection of abstract procedures that can be implemented by unrelated classes

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

How is aggregration and composition drawn

A

Aggregration : weaker so unfilled diamond arrow head
Composition : stronger so filled diamond arrow head

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

Benefit of principle ‘Favour composition over inheritance’

A

Easier to test each class using unit testing
There can be unintended side effects for derived classes if a base class is altered.

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