Unit 12 - Functional and Object Oriented Programming Flashcards
What are the properties of a first class object?
- It can be assigned to a variable
- It can appear in an expression
- It can be returned in a function call
- It can be assigned as an argument
Define encapsulation
Self containing attributes and methods within a class so they cannot be altered in other parts of the program
Define inheritance
Where a subclass inherits the attributes of a superclass in order to perform different methods
Define composition
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)
Define aggregation
When one object can own or access another object in a different class
Define polymorphism
Allowing a method in the class hierarchy to behave differently in each class
Define overriding
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)
Define overloading
Using the same methods but varying the parameters assigned to them .e.g. using ‘*args’ (an example of polymorphism)
Define method
A function assigned to a class
Define attribute
A piece of data assigned to a class
Define instantiation
Creating an object
Define object
An instance of a class
Define class
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
Define constructor
A function used to create objects based on the class
Define default constructor
One that does not accept any additional arguments
Define parameterised constructor
One that accepts arguments in addition to the default
Define interface
A collection of methods with no implementation
Define method signature
The name of the method and the parameters it includes
Define programming paradigm
A style of programming
Define function
A rule that assigns an output from a co-domain to an input from a domain without using all the outputs
Define domain
The set from which a functions inputs are chosen
Define co-domain
The set from which a functions outputs are chosen
Define immutability
A property of a program which means it’s variables cannot change
Define stateless
A program that does not record any data because none of the variables within the program change
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
Define function application
When arguments are applied to a function
Define composition of functions
Combining two functions in order to get a new function
Define partial function application
Decomposing larger functions with multiple arguments into smaller functions with fewer arguments
Define high order function
A function that takes a function as an argument or returns a function as an output or does both
Define prepending
Adding an item to the start of a list
Define appending
Adding an item to the end of a list
Define concatentation
Adding two lists together to get a new list
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
What are the four main programming paradigms?
Procedural programming, object oriented programming, functional programming and
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
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
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
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
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
What is the most common method of encapsulation within OOP?
Classes
Give one example of information hiding
Encapsulation
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
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
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
What determines which version of a method and which is overwritten?
The object being referred to
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
Describe composition
A relationship in which two objects are entirely reliant on one another and cannot exist independently
What is the symbol for aggregation?
A diamond with no fill and a line
What is the symbol for composition?
A solid diamond with a line
What is an abstract method?
One that has a declaration without implementation, this means that it relies on subclasses to carry out methods
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
What are abstract methods used for?
To create interfaces, blueprints that have data inputted later on
Why are interfaces useful in OOP?
They make codes more reusable and reduces the dependency on implementation
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
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
What is the condition about the domain and co-domain in functional programming?
They both have to be subsets of the same data type
What are the advantages of function programming?
- Less prone to bugs
- Easier to predict the outcome of the code
- Easier to write the code correctly
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
Functions are an example of what in functional programming?
First class objects
What is a property of functional programmings that is reliant on immutable variables?
Referential transparency
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
What is ‘f(g(x))’ an example of?
Composition of functions
Describe function application
The process of applying data to a function
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
How would you describe a 1 dimensional list in terms of concatentation?
A concatenation between the head and the tail of the list
What three properties are assigned to Big Data?
Volume, variety and velocity
What does volume mean in terms of Big Data?
The data is too great in volume to be stored on one server
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
What does variety mean in terms of Big Data?
The data is being generated in several different formats and can be structured or unstructured
What does map do?
Takes a function and applies it to every value in a data set and creates a new list from this
What does the fold function do?
Applies a function recursively to every value in a list to produce a single value
What does the filter function do?
Return all the values in a list that apply to a specific criteria, known as a predicate
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
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
Why are graph schemas useful?
They can be used to identify patterns that help optimise a system
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
What are properties of a graph schema?
Nodes = core entities in the data set
Properties = information about the nodes
Edges = relationships between the nodes
What is the class diagram symbol for a public method?
+
What is the class diagram symbol for a protected method?
#
What is the class diagram symbol for a private method?
-
What is a public method?
A method that can be accessed from anywhere in the program
How many underscores does a public method have?
None
What is a protected method?
A method that can be accessed from a class and any subclasses of that class
How many underscores does a protected method have?
1
What is a private method?
A method that can only be accessed from the class it was defined in
How many underscores does a private method have?
2
Define association
The relationship between two classes
What are the advantages of OOP?
- Easier to consider objects than procedures
- Classes promote and support code reuse
- Classes are highly modular and easy to maintain
- Encapsulation provides a high level of protection for data
What are the disadvantages of OOP?
- OOP can result in much larger, complex systems
- Objects can take up a large amount of memory
- Inheritance can have unintended consequences (you inherit access to methods which shouldn’t be possible .e.g. pigs could fly)
What techniques do you need for dealing with Big Data?
Machine learning