2.1 Flashcards
2.1.1 - OOP
1. What is a class?
2. What is instantiation?
- A class contains a class name, attribute and methods. A class is a template used to create an object.
- Instantiation is the process of creating an object from a class template. A constructor is a procedure that runs when an object with the class type is created.
2.1.1 - OOP
What is the structure of a class in pseudocode?
class Person
- The class starts with the keyword ‘class’ followed by the class name.
private name
- The attributes are listed next with the private keyword.
public procedure new(givenName, givenAge)
name = givenName
age = givenAge
end procedure
- Then there is the constructor method, which runs every time an object of that class type is created, taking the values of the parameters passed in and setting its local attributes to their initial values.
public procedure getName()
return name
end procedure
public procedure setName(newName)
name = newName
end procedure
- The methods are then listed for the class, which can set new values for attributes or return existing values for attributes.
endclass
- To end the class definition, we use the keyword endclass.
2.1.1 - OOP
1. How do you create a new object?
2. How do you reference methods in the class?
- To create a new object, you use this format: objectName = new ClassName(parameters).
- You use dot notation; for example personOne.getName, personTwo.setName(“Dan”).
2.1.1
1. How do you write a getter method for a class?
2. How do you write a setter method for a class?
- public function getVariableName():
return variableName
end function - public function setVariableName(newVariableName):
variableName = newVariableName
end function
2.1.1
1. State reasons why abstraction is needed in a program
2. Describe the difference between a virtual version of a place with abstraction applied, compared to the real version
- Abstraction simplifies the programming and therefore reduces cost.
- Reality contains things that aren’t relevant to a computer program
- Abstraction reduces memory requirements.
- Abstraction simplifies the programming and therefore reduces cost.
- Features are removed, for example there may be no trees or footpaths.
- Symbols or keys are used to represent elements, such as a train.
- It may not be to scale, as relative distances may not be true.
- Features are removed, for example there may be no trees or footpaths.
- Define computational thinking
- What are the different elements of a flowchart?
- What are the general rules of flowcharts?
- Computational thinking is an approach to problem solving that combines critical thinning and computer processes.
- The start and stop are in rectangles with curved sides.
- A process is in a rectangle.
- An input or output is in a parallelogram.
- A decision is in a diamond.
- Arrows show the flow of data.
- The start and stop are in rectangles with curved sides.
- All boxes of the flowchart are connected with arrows.
- Flowcharts have one entry point at the top, and one exit.
- The decision symbol has only two exit points, which can be on the sides or the bottom.
- There is one action per process.
- All boxes of the flowchart are connected with arrows.
2.1.1
1. What is computational thinking?
2. What is abstraction?
3. Why is abstraction used?
- Computational thinking is an approach to problem solving combining critical thinking and computer processes.
- Abstraction means the process of taking away or removing characteristics from something in order to reduce it to a set of essential characteristics.
- It reduces the complexity of a program, reduces the time to find a solution, reduces the design and programming time, reduces computational resources,, reduces the cost of designing and building the program, and focuses on the main purpose of the program.
2.1.1
What are the different types of abstraction?
Data abstraction: variables, objects, and data structures.
Variables: represents real world values.
Objects: in OOP a class is an abstract representation of something with certain properties (attributes) and operations (methods).
Data structures: arrays, linked-lists, stacks and queues.
Problem abstraction: when faced with a problem deciding which factors are relevant to the problem and the solution.