Unit 12 - Functional and Object Oriented Programming Flashcards

1
Q

What are the properties of a first class object?

A
  1. It can be assigned to a variable
  2. It can appear in an expression
  3. It can be returned in a function call
  4. It can be assigned as an argument
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Define encapsulation

A

Self containing attributes and methods within a class so they cannot be altered in other parts of the program

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

Define inheritance

A

Where a subclass inherits the attributes of a superclass in order to perform different methods

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

Define composition

A

A type of aggregation where two classes are reliant on one another, this means they cannot exist independently of one another (if one is deleted the other is deleted as well)

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

Define aggregation

A

When one object can own or access another object in a different class

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

Define polymorphism

A

Allowing a method in the class hierarchy to behave differently in each class

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

Define overriding

A

An attribute or method from a superclass being redefined and extended into a subclass allowing it to behave differently in different classes (an example of polymorphism)

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

Define overloading

A

Using the same methods but varying the parameters assigned to them .e.g. using ‘*args’ (an example of polymorphism)

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

Define method

A

A function assigned to a class

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

Define attribute

A

A piece of data assigned to a class

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

Define instantiation

A

Creating an object

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

Define object

A

An instance of a class

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

Define class

A

A blueprint for an object which defines the attributes for that object and the methods that act on them in order to represent the common characteristics and behaviours of that object

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

Define constructor

A

A function used to create objects based on the class

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

Define default constructor

A

One that does not accept any additional arguments

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

Define parameterised constructor

A

One that accepts arguments in addition to the default

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

Define interface

A

A collection of methods with no implementation

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

Define method signature

A

The name of the method and the parameters it includes

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

Define programming paradigm

A

A style of programming

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

Define function

A

A rule that assigns an output from a co-domain to an input from a domain without using all the outputs

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

Define domain

A

The set from which a functions inputs are chosen

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

Define co-domain

A

The set from which a functions outputs are chosen

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

Define immutability

A

A property of a program which means it’s variables cannot change

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

Define stateless

A

A program that does not record any data because none of the variables within the program change

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

Define referential transparency

A

The idea that functions written in the functional programming paradigm will always return the same result if the same variables are entered because data is immutables

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

Define function application

A

When arguments are applied to a function

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

Define composition of functions

A

Combining two functions in order to get a new function

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

Define partial function application

A

Decomposing larger functions with multiple arguments into smaller functions with fewer arguments

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

Define high order function

A

A function that takes a function as an argument or returns a function as an output or does both

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

Define prepending

A

Adding an item to the start of a list

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

Define appending

A

Adding an item to the end of a list

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

Define concatentation

A

Adding two lists together to get a new list

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

Define big data

A

Data that is collected on such a large scale it cannot be stored in one server and it cannot be analysed easily

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

What are the four main programming paradigms?

A

Procedural programming, object oriented programming, functional programming and

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

Why is a default constructor necessary for a class?

A

A constructor is responsible for assigning values to attributes of a class when an instance of the class is created, this means it creates references to attributes dependent on objects

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

What is the main difference between OOP and procedural programming?

A

Procedural programming is heavily reliant on utilising sets of global and local variables to achieve the end result whereas OOP relies on instances of classes being created (objects) which perform functions and can interact with other objects

37
Q

Describe the way in which a class operates in OOP

A

A class is responsible for ensuring an object is formed correctly and that the correct attributes and methods are associated with each object to be created. It acts as a blueprint and assigns sets pieces of data to attributes when a new object is created

38
Q

What is the difference between a parameterised constructor and a default constructor?

A

A parameterised constructor takes multiple arguments whereas a default constructor uses a single argument which is a reference to the instance of the class created

39
Q

Why is encapsulation beneficial in OOP?

A

It means that data can be protected from being edited in the wrong parts of the program and places restrictions on access to different attributes and methods

40
Q

What is the most common method of encapsulation within OOP?

A

Classes

41
Q

Give one example of information hiding

A

Encapsulation

42
Q

What is the difference between a setter and a getter?

A

A setter is a method that allows you to set the value of an attribute whereas a getter is a method that allows you to retrieve the value of an attribute

43
Q

Why is inheritance used?

A

It enables classes to take on the properties and methods of others so that they can be built on .e.g. the class Cat would be a subclass of the class Animal

44
Q

How is polymorphism used?

A

It is used to change how a method acts by changing properties such as the data types used or the number of arguments given

45
Q

What determines which version of a method and which is overwritten?

A

The object being referred to

46
Q

Explain aggregation

A

A unidirectional relationship between two objects which means one can access properties of the other, .e.g. methods or attributes, whilst remaining independent

47
Q

Describe composition

A

A relationship in which two objects are entirely reliant on one another and cannot exist independently

48
Q

What is the symbol for aggregation?

A

A diamond with no fill and a line

49
Q

What is the symbol for composition?

A

A solid diamond with a line

50
Q

What is an abstract method?

A

One that has a declaration without implementation, this means that it relies on subclasses to carry out methods

51
Q

What is a virtual method?

A

This is a method which allows itself to be overridden by a method with the same class signature, this means that the method called is dependent on the object types

52
Q

What are abstract methods used for?

A

To create interfaces, blueprints that have data inputted later on

53
Q

Why are interfaces useful in OOP?

A

They make codes more reusable and reduces the dependency on implementation

54
Q

How is an interface constructed?

A

It is a collection of method signatures which means that it includes names of functions, parameters data types and return data types but has no implementation

55
Q

What does the functional paradigm do on the function level?

A

Takes a domain and maps each value to a value from the co-domain based on the algorithm in the function which defines the purpose of the program

56
Q

What is the condition about the domain and co-domain in functional programming?

A

They both have to be subsets of the same data type

57
Q

What are the advantages of function programming?

A
  1. Less prone to bugs
  2. Easier to predict the outcome of the code
  3. Easier to write the code correctly
58
Q

Why does functional programmings have so many benefits?

A

Variables are immutable and stateless which means that they cannot change so the function will have the same output every time if you enter the same data which means it is easier to predict the outcome

59
Q

Functions are an example of what in functional programming?

A

First class objects

60
Q

What is a property of functional programmings that is reliant on immutable variables?

A

Referential transparency

61
Q

What does ‘f(g(x))’ mean?

A

The output of entering x into the function g(x) is used as the input for the f(x) function which returns the final output

62
Q

What is ‘f(g(x))’ an example of?

A

Composition of functions

63
Q

Describe function application

A

The process of applying data to a function

64
Q

How does partial function application work?

A

It takes advantage of the fact that Haskell only takes one argument at a time and it decomposes multi-argument functions into smaller functions with fewer arguments

65
Q

How would you describe a 1 dimensional list in terms of concatentation?

A

A concatenation between the head and the tail of the list

66
Q

What three properties are assigned to Big Data?

A

Volume, variety and velocity

67
Q

What does volume mean in terms of Big Data?

A

The data is too great in volume to be stored on one server

68
Q

What does velocity mean in terms of Big Data?

A

The data is being generated continuously from multiple different sources and the system has seconds to milliseconds to respond

69
Q

What does variety mean in terms of Big Data?

A

The data is being generated in several different formats and can be structured or unstructured

70
Q

What does map do?

A

Takes a function and applies it to every value in a data set and creates a new list from this

71
Q

What does the fold function do?

A

Applies a function recursively to every value in a list to produce a single value

72
Q

What does the filter function do?

A

Return all the values in a list that apply to a specific criteria, known as a predicate

73
Q

What is an advantage of the map and fold function?

A

It can be easily parallelised so multiple computers can work on a data set without affecting the other parts

74
Q

What does it mean for Big Data to work on a fact based model?

A

It records individual facts rather than records and then builds up a graph schema based on these facts which demonstrates the relationship between them

75
Q

Why are graph schemas useful?

A

They can be used to identify patterns that help optimise a system

76
Q

Which programming paradigm solves the problem of not being able to store Big Data on a single server and why?

A

Functional programming, it has referential transparency which means that multiple different programs can work on the same dataset without affecting each other

77
Q

What are properties of a graph schema?

A

It has nodes and edges

78
Q

What is the class diagram symbol for a public method?

A

+

79
Q

What is the class diagram symbol for a protected method?

A

#

80
Q

What is the class diagram symbol for a private method?

A

-

81
Q

What is a public method?

A

A method that can be accessed from anywhere in the program

82
Q

How many underscores does a public method have?

A

None

83
Q

What is a protected method?

A

A method that can be accessed from a class and any subclasses of that class

84
Q

How many underscores does a protected method have?

A

1

85
Q

What is a private method?

A

A method that can only be accessed from the class it was defined in

86
Q

How many underscores does a private method have?

A

2

87
Q

Define association

A

The relationship between two classes

88
Q

What are the advantages of OOP?

A
  1. Easier to consider objects than procedures
  2. Classes promote and support code reuse
  3. Classes are highly modular and easy to maintain
  4. Encapsulation provides a high level of protection for data
89
Q

What are the disadvantages of OOP?

A
  1. OOP can result in much larger, complex systems
  2. Objects can take up a large amount of memory
  3. Inheritance can have unintended consequences (you inherit access to methods which shouldn’t be possible .e.g. pigs could fly)