4.1 - Fundamentals of programming Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Define ‘subroutine’.

A

A named section of code that can be called by writing the subroutine’s name in a program statement

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

What are the 3 advantages of using subroutines?

A

Makes the code more readable and reusable - code is broken into smaller sections

Most programming languages come with a standard library of built-in subroutines to perform common functions

Pre-written libraries of code come from a reliable source - will hopefully be well-tested as they will have been used in a large number of different programs

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

Define ‘local variable’ and ‘global variable’.

A

Local variable - a variable that can only be accessed from the subroutine within which it is declared

Global variable - a variable that can be accessed from any part of a program and exist in memory for the entire duration of the program’s execution

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

What are 3 things that are stored using a stack frame?

A

Return addresses

Parameters

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
5
Q

What is a recursive subroutine and what is a base case?

A

Recursive subroutine - a function that calls itself until a base case is met

Base case - the condition(s) at which the subroutine is no longer called

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

What is the structured approach to programming? (3 points)

A

Designed from the top down

Most important elements of a problem are broken down into smaller tasks

Each of which can be solved in a block of code such as a procedure or module which goes on to form part of the overall solution

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

What are the 2 advantages of the structured approach to programming?

A

Makes maintaining the program easier - navigation of different elements of the overall solution is improved

Testing can be carried out on the individual modules before they are combined to form the overall solution

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

What is a class?

A

A blueprint for objects that specifies what properties (data) and methods (instructions) objects of their type will have

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

What is an object? (2 points)

A

Anything that we can name and describe

Things that we want to model within our programs - anything that exists in the real world that has some specific meaning

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

Define ‘instantiation’.

A

The process of making an object from the class definition

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

Define ‘encapsulation’.

A

The process of combining methods and procedures to form an object

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

Define ‘inheritance’.

A

Is-A - allowing one class to share the properties and methods of another class while having its own properties and methods too

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

Define ‘aggregation’. (2 points)

A

The weaker of the two kinds of association (Has-A)

The object can exist independently of the object it is associated with

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

Define ‘composition’.

A

A stronger relationship between classes (Has-A aka Part of)

The object is deleted if the object it is associated with is deleted

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

Define ‘polymorphism’.

A

Objects of different classes/types responding differently to the use of a common interface/the same usage

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

Define ‘overriding’.

A

When a method has the same name as a method in an inherited class but different implementation

17
Q

What are the 4 advantages of OOP?

A

Usually easier for us to think in terms of objects than to think procedurally - we are surrounded by objects in the real world which have attributes which are easy to think of

Prewritten classes promote and support code reuse - in a large organisation, there are likely to be prewritten classes for common objects which programmers can make use of without rewriting any definitions

Classes are highly modular, making them easy to maintain - if an object needs an extra attribute, you only need to go to one place to add it

Encapsulation provides a high level of protection for data - preventing direct access to private attributes ensures that the data can never be modified carelessly

18
Q

What are the 4 disadvantages of OOP?

A

OOP design techniques often make it easier to fully model a complete system, but it can also result in a much larger, more complex system being built in order to achieve the results

Detrimental to performance due to relying on
high volumes of message passing

Inheritance can have unintended consequences - objects can acquire the ability to do things that don’t make sense

Objects can take up a relatively large amount of memory - can be an issue if there are hardware restrictions

19
Q

What are the 3 OOP principles?

A
  1. Encapsulate what varies - any requirements which are likely to change should be encapsulated in a class so that changes can be easily made
  2. Favour composition over inheritance - seen as a more flexible relationship between objects
  3. Program to interfaces, not implementation - allows unrelated classes to make use of similar methods
20
Q

What are public, protected and private attributes/methods?

A

Public - can be accessed from anywhere in the program

Protected - can be directly accessed by a subclass

Private - can only be accessed from within the class