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
Define referential transparency
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
26
Define function application
When arguments are applied to a function
27
Define composition of functions
Combining two functions in order to get a new function
28
Define partial function application
Decomposing larger functions with multiple arguments into smaller functions with fewer arguments
29
Define high order function
A function that takes a function as an argument or returns a function as an output or does both
30
Define prepending
Adding an item to the start of a list
31
Define appending
Adding an item to the end of a list
32
Define concatentation
Adding two lists together to get a new list
33
Define Big data
Data that is collected on such a large scale it cannot be stored in one server and it cannot be analysed easily
34
What are the four main programming paradigms?
Procedural programming, object oriented programming, functional programming and
35
Why is a default constructor necessary for a class?
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
36
What is the main difference between OOP and procedural programming?
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
Describe the way in which a class operates in OOP
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
What is the difference between a parameterised constructor and a default constructor?
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
Why is encapsulation beneficial in OOP?
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
What is the most common method of encapsulation within OOP?
Classes
41
Give one example of information hiding
Encapsulation
42
What is the difference between a setter and a getter?
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
Why is inheritance used?
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
How is polymorphism used?
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
What determines which version of a method and which is overwritten?
The object being referred to
46
Explain aggregation
A unidirectional relationship between two objects which means one can access properties of the other, .e.g. methods or attributes, whilst remaining independent
47
Describe composition
A relationship in which two objects are entirely reliant on one another and cannot exist independently
48
What is the symbol for aggregation?
A diamond with no fill and a line
49
What is the symbol for composition?
A solid diamond with a line
50
What is an abstract method?
One that has a declaration without implementation, this means that it relies on subclasses to carry out methods
51
What is a virtual method?
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
What are abstract methods used for?
To create interfaces, blueprints that have data inputted later on
53
Why are interfaces useful in OOP?
They make codes more reusable and reduces the dependency on implementation
54
How is an interface constructed?
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
What does the functional paradigm do on the function level?
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
What is the condition about the domain and co-domain in functional programming?
They both have to be subsets of the same data type
57
What are the advantages of function programming?
1. Less prone to bugs 2. Easier to predict the outcome of the code 3. Easier to write the code correctly
58
Why does functional programmings have so many benefits?
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
Functions are an example of what in functional programming?
First class objects
60
What is a property of functional programmings that is reliant on immutable variables?
Referential transparency
61
What does 'f(g(x))' mean?
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
What is 'f(g(x))' an example of?
Composition of functions
63
Describe function application
The process of applying data to a function
64
How does partial function application work?
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
How would you describe a 1 dimensional list in terms of concatentation?
A concatenation between the head and the tail of the list
66
What three properties are assigned to Big Data?
Volume, variety and velocity
67
What does volume mean in terms of Big Data?
The data is too great in volume to be stored on one server
68
What does velocity mean in terms of Big Data?
The data is being generated continuously from multiple different sources and the system has seconds to milliseconds to respond
69
What does variety mean in terms of Big Data?
The data is being generated in several different formats and can be structured or unstructured
70
What does map do?
Takes a function and applies it to every value in a data set and creates a new list from this
71
What does the fold function do?
Applies a function recursively to every value in a list to produce a single value
72
What does the filter function do?
Return all the values in a list that apply to a specific criteria, known as a predicate
73
What is an advantage of the map and fold function?
It can be easily parallelised so multiple computers can work on a data set without affecting the other parts
74
What does it mean for Big Data to work on a fact based model?
It records individual facts rather than records and then builds up a graph schema based on these facts which demonstrates the relationship between them and all of the facts are time stamped so the facts were true at the time
75
Why are graph schemas useful?
They can be used to identify patterns that help optimise a system
76
Which programming paradigm solves the problem of not being able to store Big Data on a single server and why?
Functional programming, it has referential transparency which means that multiple different programs can work on the same dataset without affecting each other
77
What are properties of a graph schema?
Nodes = core entities in the data set Properties = information about the nodes Edges = relationships between the nodes
78
What is the class diagram symbol for a public method?
+
79
What is the class diagram symbol for a protected method?
#
80
What is the class diagram symbol for a private method?
-
81
What is a public method?
A method that can be accessed from anywhere in the program
82
How many underscores does a public method have?
None
83
What is a protected method?
A method that can be accessed from a class and any subclasses of that class
84
How many underscores does a protected method have?
1
85
What is a private method?
A method that can only be accessed from the class it was defined in
86
How many underscores does a private method have?
2
87
Define association
The relationship between two classes
88
What are the advantages of OOP?
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
What are the disadvantages of OOP?
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)
90
What techniques do you need for dealing with Big Data?
Machine learning