Section 12: Object-Oriented Programming and Functional Programming Flashcards

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

Chapter 67:

What is Object-Oriented Programming.

A

Where the world is looked at as a collection of objects.

Objects are represented as complex data structures consisting of different attributes and methods.

Objects are instances of Classes; Classes define attributes and methods.

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

Chapter 67:
What is an attribute?
What would be an attribute of a car object?

A

An object-bound variable.

Brand / Colour / Engine Size.

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

Chapter 67:
What is a method?
What would be a method of a car object?

A

An object-bound function or procedure.

Accelerate / Break.

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

Chapter 67:

What are the 4 main concepts in OOP?

A

Instantiation,
Encapsulation,
Inheritance,
Polymorphism.

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

Chapter 67:

What is Encapsulation?

A

Making attributes hidden, and creating messages to access them.

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

Chapter 67:

What are messages in OOP?

A

Getters and Setters.

Methods that return the value of a private attribute or change the value of a private attribute.

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

Chapter 67:

What is Inheritance?

A

Where one class copies the attributes and methods of another class into itself. Other methods and attributes can then be added to personalise the subclass.

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

Chapter 67:

What do we call the different types of classes involved in Inheritance?

A

Super Class - Parent Class

Sub Class - Child Class

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

Chapter 67:

What rule do we use to determine whether Inheritance is appropriate?

A

The “is an X a Y” / “is a” rule

For Example:
Is a Cat an Animal?
Yes, therefore Cat should be a subclass of Animal.

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

Chapter 68:

What is Association?

A

Related but independent classes.

“X has a Y” / “has a” rule.

For Example:
A teacher has a student.
A student has a teacher.
They are Associated, but there is no Ownership between them.

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

Chapter 68:

What is Aggregation?

A

When one class is contained by another (e.g. A player is part of a team), and the object (player) is not destroyed when the container (team) is destroyed. (The player does not cease to exist if the team disbands).

This can be represented with a hollow diamond on a graph. (With the diamond by the container).

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

Chapter 68:

What is Class Composition?

A

When one class is contained by another (e.g. A room is part of a hotel), and the object (room) is destroyed when the container (hotel) is destroyed. (When a hotel is destroyed, the rooms are as well).

This can be represented with a solid diamond on a graph. (With the diamond by the container).

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

Chapter 68:
Association can be Unidirectional or Bidirectional.
What is the difference? Give examples.

A

Unidirectional is one-way.
Bidirectional is two-way.

Examples:
Unidirectional: Customer places an Order.
Bidirectional: A is married to B, B is married to A.

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

Chapter 68:

What is Polymorphism?

A

As an extension of Inheritance, Polymorphism is where methods are changed for a specific subclass.

For example:
With a superclass Animal, you may have a method moveLeft() which decrements the posX attribute for the object by 3 spaces.
If you have subclasses Cat and Mouse, the mouse may not be able to move 3 spaces at once, so Polymorphism may be used to override the moveLeft() method, so that the posX attribute is decremented by 2 spaces.

Alternatively, you could define a specialMove() method, and have a subclass that completely changes the contents of the method, just keeping the same name.

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

Chapter 68:

How is Polymorphism achieved?

A

By overriding methods.

By defining a method of the same name and parameters as the inherited method.

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

Chapter 68:
Inheritance or Composition;
Which is preferable, and why?

A

Composition.

With Composition, you are not bound by the tree structure of Inheritance.

If you have a specific object [for example a robot dog] you would need to inherit certain methods and attributes from a subclass [dog might be a subclass of animal]. If you then don’t want your specific object to inherit from the superclass, you would have to either duplicate code, or give the specific object more methods than they need.

With Composition, you define the methods that you need, and then define your classes with access to certain methods.

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

Chapter 68:

What are the 3 Access Modifiers / Access Specifiers?

A

Public
Private
Protected

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

Chapter 68:

What is the Public Access Modifier / Access Specifier?

A

The member is accessible from outside of the class.

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

Chapter 68:

What is the Private Access Modifier / Access Specifier?

A

The member is only accessible inside of the class.

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

Chapter 68:

What is the Protected Access Modifier / Access Specifier?

A

The member is accessible within the class, and within subclasses.

Depending on the programming language, the member may or may not be accessible by classes in the same package.

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

Chapter 68:

What is the structure of a Class Diagram?

A

1x3 table.

Name in the top.
Attributes in middle.
Methods at the bottom.

Public indicated by ‘+’
Private indicated by ‘-‘
Protected indicated by ‘#’

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

Chapter 68:

What is an interface in OOP?

A

When multiple objects require the same set of methods, an interface could be used to collect all of the shared methods and then referenced as one call in the different objects.

For example
SwitchOn()
SwitchOff()
SetTimer(time)
GetTimer()
...

May be used by a microwave, a lighting system, a computer or many other objects. The listed methods could be placed in an interface called Switches, for example, and the objects could implement the interface, rather than repeating several method definitions.

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

Chapter 68:

What are the advantages of Object-Oriented Programming?

A

The methodology forces designers to plan thoroughly, making for better designs with fewer weaknesses.

Once an object is created, knowledge of the implementation is not required for use. This is especially important for collaborative projects.

New objects, slightly different from others can be created easily.

Easier to maintain, as the structure is enforced.

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

Chapter 68:

What are the disadvantages of Object-Oriented Programming?

A

It can be inefficient, as the structure can sometimes be more memory and CPU intensive than alternative methods.

Requires time and planning, which can slow down a project. This could lead to missing deadlines.

For less intensive projects, Object-Oriented structure can make the code look bloated, as efficiency may not be drastically improved, while complexity will drastically increase.

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

Chapter 69:

What is a programming paradigm?

A

Different styles of programming.

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

Chapter 69:

What are the 2 main types of Programming Paradigm?

A
Imperative.
    - Procedural.
    - Object-Oriented.
Declarative.
    - Functional.
27
Q

Chapter 69:

What are Imperative Programming Paradigms used for?

A

Imperative Programming Languages focus on how to execute. A series of steps is written to achieve a goal.

28
Q

Chapter 69:

What are Declarative Programming Paradigms used for?

A

Declarative Programming Languages focus on what to execute. Control flow is not defined by the programmer.

29
Q

Chapter 69:

What is a Procedural Programming Language?

A

Just a sequence of steps using sequence, selection, iteration, and recursion.

30
Q

Chapter 69:

What is an Object-Oriented Programming Language?

A

Objects with different properties (attributes) and functions (methods) are used to model a problem or situation.

31
Q

Chapter 69:

What is a Functional Programming Language?

A

Instead of having a program flow, functions are defined in reference to inputs.
Variables cannot be defined.

32
Q

Chapter 69:

What is a Function?

A

Entering a value (domain) will return an output (co-domain).

Entering the same value will return the same output. (Unless the function makes use of Random Number Generation).

33
Q

Chapter 69:

What is an example of a Functional Programming Language?

A

Haskell.

34
Q

Chapter 69:

Is SQL a Functional Programming Language?

A

No.

SQL is Declarative, but not Functional.

35
Q

Chapter 69:
‘Parameter’ and ‘Argument’ are often used interchangeably.
What is the distinction?

A

Arguments is a value or expression.

Parameter is a reference to the value or expression.

36
Q

Chapter 69:

What is the name of the process of giving particular inputs to a function?

A

Function Application.

37
Q

Chapter 69:

What is a First-Class Object?

A
An Object that can be:
assigned to a variable,
appear in expressions,
be assigned as an argument,
be returned in a function call.
38
Q

Chapter 69:
Functional Language functions are said to have no side effects.
What does this mean?

A

They cannot change the value of any object.

39
Q

Chapter 69:
What is Referential Transparency?
Why is it useful?

A

Where a function called with the same parameters will always return the same result.

It makes it easier for programmers to write bug-free programs. It makes the program more predictable.

40
Q

Chapter 69:

What is Function Composition?

A

When multiple functions are combined.

e.g.
f(g(x))

41
Q

Chapter 69:

How do you represent f(g(x)) in Haskell?

A

(g.f) {input}

42
Q

Chapter 69:

What are Types and Typeclasses in Haskell?

A

Types = sets of values.

Typeclasses = sets of types.

43
Q

Chapter 70:

What is a Higher-Order Function?

A

A function that takes another function as a parameter or returns a function as a result. (Or both).

44
Q

Chapter 70:

What are some examples of Higher-Order Functions?

A

Map, Filter, Fold(/Reduce).

45
Q

Chapter 70:
Haskell only takes one parameter at a time.
How does this work?

A

The program takes the first parameter and returns a new function where the first parameter has been evaluated.
The second parameter is then passed into the returned function.

This continues for all parameters.

46
Q

Chapter 70:

What is Partial Function Application?

A

Where you create a function that calls another function with a predefined parameter.
Partial Application is fixing/binding some inputs to a function to produce another more specific function.

e. g.
function: add

addSix = add

addSix 10
» 16

47
Q

Chapter 70:

What does the Map function do?

A

Map is a higher-order function that takes a function and a list as parameters.
Every item in the list is passed through the function and the results are stored to a new list. The new list is returned.

e. g.
function: Square x = x * x
list: Values = [1, 2, 3, 4]

Map(Square, Values)
» [1, 4, 9, 16]

48
Q

Chapter 70:

What does the Filter function do?

A

Filter is a higher-order function that takes a predicate function and a list as parameters.
Every item in the list is passed through the function. The function will return true or false. The returned value will be a sublist of all items that returned true.

e. g.
function: IsEven x = bool(x mod 2 == 0)
list: Values = [1, 2, 3, 4]

Filter(IsEven, Values )
» [2, 4]

49
Q

Chapter 70:

What is a predicate?

A

An expression which is either affirmed or denied.

Returns true or false.

50
Q

Chapter 70:

What does the Fold function do?

A

Fold is a higher-order function that takes a function, an initial value and a list of parameters.
The initial value and the first item in the list are combined using the function. This value is then combined with the next item in the list to give a new result. This passes through the whole list and returns a single value.

e.g.
foldL (+) 0 [2, 3, 4, 5]
» 14

Parenthesised as
(((0 + 2) + 3) + 4) + 5

foldL = fold left, i.e. start with the leftmost value.
foldR = fold right, i.e. start with the rightmost value.
[In this case the result would be the same as addition is commutative].

51
Q

Chapter 71:

What are the two parts to a List?

A

Head and Tail.
Head = first item in list.
Tail = every other item in list.

52
Q

Chapter 71:
What is the Head of a List?
What is the Tail of a List?

A

Head is the first element in the list.

Tail is a sublist of all the items in the list except for the head. (The rest of the list).

53
Q

Chapter 71:

What are the two main ways to add an item to a list?

A

Prepending = Add a new item to the front of the list.

Appending = Add a new item to the back of the list.

54
Q

Chapter 72:

What is Big Data?

A

When you have so much data that traditional methods of organisation and analysis can no longer be viably used.

55
Q

Chapter 72:

What are the 3 parts to Big Data?

A

Volume (Size),
Velocity (Access Latency),
Variety (What the data can be).

56
Q

Chapter 72:

What does Big Data allow us to do?

A

Detect and Analyse relationships in a field.

57
Q

Chapter 72:

How is Big Data used in Healthcare?

A

Doctors can collect data such as symptoms, or blood pressure, on patients and compare the data to others to try and diagnose problems and find solutions.

58
Q

Chapter 72:

*How much data does Google process every day?

A

20 Petabytes.

59
Q

Chapter 72:

*How many search queries does Google receive every day?

A

3 Billion.

60
Q

Chapter 72:

How did Google help health officials in 2009?

A

During an outbreak of H1N1, Google was able to identify its spread far more quickly that government statistics.

61
Q

Chapter 72:

How does Amazon use Big Data?

A

To improve book recommendations.

A conventional method would be to look at a book’s metadata and search for other books that are similar, but this isn’t optimal as if, for example, you wanted to read a book about how to program in python, you are unlikely to want another book about the same topic.

Amazon used Big Data to see, given a book, selecting people who have read that same book, what else they read and enjoy.

62
Q

Chapter 72:

What is the Fact-Based Model?

A

An alternative to the Relational Data Model.

Fact-Based Model records immutable facts with timestamps. This means that previous data cannot be changed, but new data can be used instead.

63
Q

Chapter 72:

What is Graph Schema?

A

Where data is stored as nodes and relationships, and both nodes and relationships have properties.

64
Q

Chapter 72:

What makes Graph Schema better than Relational?

A

If, for example, you want to search a network of people for people that are friends with Steve:

In a Relational Database, you would need to search the whole database for everyone that has Steve as a friend.

In Graph Schema, you only need to locate Steve, as observe the relationships.

Finding friends-of-friends would be impractical in a large Relational Database.