Fundamentals of Programming Flashcards
What is Iteration?
Repeating an instruction, this could be definite or indefinite.
What is the difference between definite iteration and indefinite iteration?
With definite iteration, the number of repetitions is known before the loop starts, however with indefinite iteration, the amount of repetitions is not known beforehand.
What is selection?
Comparing values and choosing an action based on those values.
def func(x)
return x + 2
func(5)
in the code above, what is the parameter and what is the argument?
x is the parameter and 5 is the argument
Why are local variables better to use than global variables?
local variables are more memory efficient, they also keep you code more modular.
What is a stack frame (in subroutine calls)
Stack frames are used by computers to store return addresses, parameters and local variables for each subroutine call that occurs during the execution of a program.
What is the difference between a public and private property/method in a class
private properties/methods can only be accessed from within an object, however public methods allow an interface for accessing and modifying a class’s private properties
What is encapsulation?
the process of combining methods and procedures to form an object. An object is said to encapsulate its contents, forming a single entity which encompasses all of the objects properties and methods.
What is inheritance
Classes can inherit from other classes. Inheritance allows one class to share the properties and methods of another class while having its own properties and methods too
What is polymorphism
Polymorphism occurs when objects are processed differently depending on their class. Two classes with methods that have the same name, but do different things.
What is overriding
An overrien method has the same name as a method in an inherited class but different implementation
What is association
If two objects are associated, they can be described as having a “has a” relationship. e.g for two classes Car and Driver, a Car has a Driver. There are two types of association, aggregation and composition.
What is Aggregation (type of association)
Aggregation is the weaker of the two kinds of association. When an object is associated with another by aggregation, it will still exist if its containing object is destroyed. e.g a car’s driver is associated with the car by aggregation. If the car is destroyed, the driver still exists.
What is composition (type of association)
If two objects are associated by composition and the containing object is destroyed, the associated object is also destroyed. e.g a car’s wheels is associated with the car by composition. If the car is destroyed, so are the wheels.
Why is OOP used
OOP provides programs with a clear structure that makes developing and testing programs easier for developers. It also allows code to be reused throughout the same program and even in other programs.
What name is given to the code which is run to handle an exception?
Catch block
What name is given to a type of subroutine which always returns a value
Function
What is meant by a base case?
The terminating situation in recursion that does not use recursion to produce a result.
What error will occur if a recursive subroutine never meets its base case?
Stack overflow
Name 3 OOP design principles
Encapsulate what varies
Favour composition over inheritance
Program to interfaces, not implementation
In class diagrams which type of line represents aggregation?
A line with a hollow diamond on the end
In class diagrams which type of line represents composition?
A line with a solid diamond on the end